/
flowimpl-timeout.go
57 lines (46 loc) · 1.26 KB
/
flowimpl-timeout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"context"
"github.com/jinzhu/copier"
"reflect"
"strconv"
"strings"
"time"
)
type FlowImplTimeout FlowImplBase
func (impl *FlowImplTimeout) Type() FlowImplType {
return FlowImplTypeCtrl
}
func (impl *FlowImplTimeout) Usage() string {
return impl.Name() + " <milliseconds> Setup timeout duration, by milliseconds"
}
func (impl *FlowImplTimeout) Do(args...interface{}) error {
browser := args[0].(*Browser)
timeout, _ := strconv.Atoi(impl.Command().GetFieldString(0))
browser.chromeContext, browser.chromeCancel = context.WithTimeout(
browser.chromeContext, time.Millisecond * time.Duration(timeout))
return nil
}
//go:generate make IMPL_TYPE=FlowImplTimeout gen-impl
func init() {
flowImpl := func() IFlowImpl {
return &FlowImplTimeout{}
}()
registerFlow(flowImpl)
}
func (impl *FlowImplTimeout) Name() string {
interfaceName := reflect.TypeOf(impl).String()
commandName := strings.Split(interfaceName, "FlowImpl")[1]
return strings.ToLower(commandName)
}
func (impl *FlowImplTimeout) SetCommand(command *FlowCommand) {
impl.command = command
}
func (impl *FlowImplTimeout) Command() *FlowCommand {
return impl.command
}
func (impl *FlowImplTimeout) Clone() IFlowImpl {
c := &FlowImplTimeout{}
_ = copier.Copy(c, impl)
return c
}