-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_options.go
55 lines (42 loc) · 1.53 KB
/
manager_options.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
package jasper
import (
"context"
"github.com/google/uuid"
"github.com/tychoish/fun"
"github.com/tychoish/jasper/options"
)
type ManagerOptions struct {
ID string
Tracker ProcessTracker
MaxProcs int
Synchronized bool
Remote *options.Remote
ExecutorResolver func(context.Context, *options.Create) options.ResolveExecutor
}
type ManagerOptionProvider = fun.OptionProvider[*ManagerOptions]
func ManagerOptionDefaults() ManagerOptionProvider {
return func(conf *ManagerOptions) error {
conf.ID = uuid.New().String()
conf.Synchronized = true
conf.MaxProcs = 1024
return nil
}
}
func ManagerOptionSet(opts ManagerOptions) ManagerOptionProvider {
return func(conf *ManagerOptions) error { *conf = opts; return nil }
}
func ManagerOptionMaxProcs(n int) ManagerOptionProvider {
return func(conf *ManagerOptions) error { conf.MaxProcs = n; return nil }
}
func ManagerOptionSetSynchronized() ManagerOptionProvider {
return func(conf *ManagerOptions) error { conf.Synchronized = true; return nil }
}
func ManagerOptionSetUnynchronized() ManagerOptionProvider {
return func(conf *ManagerOptions) error { conf.Synchronized = false; return nil }
}
func ManagerOptionWithRemote(opt *options.Remote) ManagerOptionProvider {
return func(conf *ManagerOptions) error { conf.Remote = opt; return nil }
}
func ManagerOptionExecutorResolver(er func(context.Context, *options.Create) options.ResolveExecutor) ManagerOptionProvider {
return func(conf *ManagerOptions) error { conf.ExecutorResolver = er; return nil }
}