-
Notifications
You must be signed in to change notification settings - Fork 50
/
module_options.go
39 lines (35 loc) · 1.23 KB
/
module_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
package kernel
type ModuleOption func(ms *moduleConfig)
// Overwrite the type a module specifies by something else.
// E.g., if you have a background module you completely depend
// on, you can do
//
// k.Add("your module", NewYourModule(), kernel.ModuleType(kernel.TypeEssential))
//
// to declare the module as essential. Now if the module quits the
// kernel will shut down instead of continuing to run.
func ModuleType(moduleTypeProvider func() TypedModule) ModuleOption {
return func(ms *moduleConfig) {
moduleType := moduleTypeProvider()
ms.essential = moduleType.IsEssential()
ms.background = moduleType.IsBackground()
}
}
// Overwrite the stage of a module. Using this, you can move a module
// of yours (or someone else) to a different stage, e.g. to make sure it
// shuts down after another module (because it is the consumer of another
// module and you need the other module to stop producing before you can
// stop consuming).
func ModuleStage(moduleStage int) ModuleOption {
return func(ms *moduleConfig) {
ms.stage = moduleStage
}
}
// Combine a list of options by applying them in order.
func MergeOptions(options []ModuleOption) ModuleOption {
return func(ms *moduleConfig) {
for _, opt := range options {
opt(ms)
}
}
}