generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvoke.go
38 lines (33 loc) · 856 Bytes
/
invoke.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
package imbue
import (
"context"
"errors"
)
// InvokeOption is an option that changes the behavior of a call to InvokeX().
type InvokeOption interface {
applyInvokeOptionToContainer(*Container) error
applyInvokeOptionToContext(*scopedContext) error
}
// filterInvokeError is called when an InvokeX() function is about to return an
// error.
//
// It may modify the error, return a new error, or panic.
func filterInvokeError(err error) error {
var u undeclaredConstructorError
if errors.As(err, &u) {
panic(u.Error())
}
return err
}
// Invoke0 calls a function without dependencies.
//
// This function does not use the container at all; it is included to aid while
// refactoring.
func Invoke0(
ctx context.Context,
con *Container,
fn func(context.Context) error,
options ...InvokeOption,
) error {
return filterInvokeError(fn(ctx))
}