@@ -10,14 +10,19 @@ To declare a function that may be executed later, call Func
10
10
in a top-level assignment context, passing it an arbitrary string key
11
11
and a function whose first argument is of type context.Context.
12
12
The key is used to look up the function so it can be called later.
13
+
13
14
var laterFunc = delay.Func("key", myFunc)
15
+
14
16
It is also possible to use a function literal.
17
+
15
18
var laterFunc = delay.Func("key", func(c context.Context, x string) {
16
19
// ...
17
20
})
18
21
19
22
To call a function, invoke its Call method.
23
+
20
24
laterFunc.Call(c, "something")
25
+
21
26
A function may be called any number of times. If the function has any
22
27
return arguments, and the last one is of type error, the function may
23
28
return a non-nil error to signal that the function should be retried.
@@ -37,9 +42,9 @@ with the string key that was passed to the Func function. Updating an app
37
42
with pending function invocations should safe as long as the relevant
38
43
functions have the (filename, key) combination preserved. The filename is
39
44
parsed according to these rules:
40
- * Paths in package main are shortened to just the file name (github.com/foo/foo.go -> foo.go)
41
- * Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -> github.com/foo/bar.go)
42
- * Module versions are stripped (/go/pkg/mod/github.com/foo/[email protected] /baz.go -> github.com/foo/bar/baz.go)
45
+ - Paths in package main are shortened to just the file name (github.com/foo/foo.go -> foo.go)
46
+ - Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -> github.com/foo/bar.go)
47
+ - Module versions are stripped (/go/pkg/mod/github.com/foo/[email protected] /baz.go -> github.com/foo/bar/baz.go)
43
48
44
49
There is some inherent risk of pending function invocations being lost during
45
50
an update that contains large changes. For example, switching from using GOPATH
@@ -208,10 +213,13 @@ type invocation struct {
208
213
}
209
214
210
215
// Call invokes a delayed function.
211
- // err := f.Call(c, ...)
216
+ //
217
+ // err := f.Call(c, ...)
218
+ //
212
219
// is equivalent to
213
- // t, _ := f.Task(...)
214
- // _, err := taskqueue.Add(c, t, "")
220
+ //
221
+ // t, _ := f.Task(...)
222
+ // _, err := taskqueue.Add(c, t, "")
215
223
func (f * Function ) Call (c context.Context , args ... interface {}) error {
216
224
t , err := f .Task (args ... )
217
225
if err != nil {
0 commit comments