Go 1.11 has reached end of support
and will be deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Go 1.11
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Go
1.11 applications will continue to run and receive traffic after their
deprecation date. We
recommend that you migrate to the latest supported version of Go.
Package delay provides a way to execute code outside the scope of a
user request by using the taskqueue API.
To declare a function that may be executed later, call Func
in a top-level assignment context, passing it an arbitrary string key
and a function whose first argument is of type context.Context.
The key is used to look up the function so it can be called later.
A function may be called any number of times. If the function has any
return arguments, and the last one is of type error, the function may
return a non-nil error to signal that the function should be retried.
The arguments to functions may be of any type that is encodable by the gob
package. If an argument is of interface type, it is the client's responsibility
to register with the gob package whatever concrete type may be passed for that
argument; see http://golang.org/pkg/gob/#Register for details.
Any errors during initialization or execution of a function will be
logged to the application logs. Error logs that occur during initialization will
be associated with the request that invoked the Call method.
The state of a function invocation that has not yet successfully
executed is preserved by combining the file name in which it is declared
with the string key that was passed to the Func function. Updating an app
with pending function invocations should safe as long as the relevant
functions have the (filename, key) combination preserved. The filename is
parsed according to these rules:
Paths in package main are shortened to just the file name (github.com/foo/foo.go -> foo.go)
Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -> github.com/foo/bar.go)
Module versions are stripped (/go/pkg/mod/github.com/foo/bar@v0.0.0-20181026220418-f595d03440dc/baz.go -> github.com/foo/bar/baz.go)
There is some inherent risk of pending function invocations being lost during
an update that contains large changes. For example, switching from using GOPATH
to go.mod is a large change that may inadvertently cause file paths to change.
The delay package uses the Task Queue API to create tasks that call the
reserved application path "/_ah/queue/go/delay".
This path must not be marked as "login: required" in app.yaml;
it must be marked as "login: admin" or have no access restriction.
Func declares a new Function. The second argument must be a function with a
first argument of type context.Context.
This function must be called at program initialization time. That means it
must be called in a global variable declaration or from an init function.
This restriction is necessary because the instance that delays a function
call may not be the one that executes it. Only the code executed at program
initialization time is guaranteed to have been run by an instance before it
receives a request.
Task creates a Task that will invoke the function.
Its parameters may be tweaked before adding it to a queue.
Users should not modify the Path or Payload fields of the returned Task.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe \u003ccode\u003edelay\u003c/code\u003e package allows the execution of code outside the scope of a user request via the taskqueue API.\u003c/p\u003e\n"],["\u003cp\u003eFunctions can be declared for delayed execution using \u003ccode\u003edelay.Func\u003c/code\u003e, which requires a string key and a function with a \u003ccode\u003econtext.Context\u003c/code\u003e as its first argument.\u003c/p\u003e\n"],["\u003cp\u003eDelayed functions are invoked with their \u003ccode\u003eCall\u003c/code\u003e method, and can be called multiple times with arguments of any type encodable by the gob package.\u003c/p\u003e\n"],["\u003cp\u003ePending function invocations are preserved by combining the file name where the function is declared with the string key passed to \u003ccode\u003eFunc\u003c/code\u003e, however, large updates can have the risk of losing these pending invocations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003edelay\u003c/code\u003e package utilizes the Task Queue API and the app's \u003ccode\u003eapp.yaml\u003c/code\u003e file must not have access restrictions on the path \u003ccode\u003e/_ah/queue/go/delay\u003c/code\u003e, it either needs to be \u003ccode\u003elogin: admin\u003c/code\u003e or no restrictions.\u003c/p\u003e\n"]]],[],null,["# Package google.golang.org/appengine/delay (v1.6.7)\n\nVersion 1.6.7keyboard_arrow_down\n\n- [1.6.8 (latest)](/appengine/docs/legacy/standard/go111/reference/latest/delay)\n- [1.6.7](/appengine/docs/legacy/standard/go111/reference/1.6.7/delay) \n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/google.golang.org/appengine/delay). \n\u003cbr /\u003e\n\nPackage delay provides a way to execute code outside the scope of a\nuser request by using the taskqueue API.\n\nTo declare a function that may be executed later, call Func\nin a top-level assignment context, passing it an arbitrary string key\nand a function whose first argument is of type context.Context.\nThe key is used to look up the function so it can be called later. \n\n```gdscript\nvar laterFunc = delay.Func(\"key\", myFunc)\n```\n\n\u003cbr /\u003e\n\nIt is also possible to use a function literal. \n\n```gdscript\nvar laterFunc = delay.Func(\"key\", func(c context.Context, x string) {\n // ...\n})\n```\n\n\u003cbr /\u003e\n\nTo call a function, invoke its Call method. \n\n```text\nlaterFunc.Call(c, \"something\")\n```\n\n\u003cbr /\u003e\n\nA function may be called any number of times. If the function has any\nreturn arguments, and the last one is of type error, the function may\nreturn a non-nil error to signal that the function should be retried.\n\nThe arguments to functions may be of any type that is encodable by the gob\npackage. If an argument is of interface type, it is the client's responsibility\nto register with the gob package whatever concrete type may be passed for that\nargument; see \u003chttp://golang.org/pkg/gob/#Register\u003e for details.\n\nAny errors during initialization or execution of a function will be\nlogged to the application logs. Error logs that occur during initialization will\nbe associated with the request that invoked the Call method.\n\nThe state of a function invocation that has not yet successfully\nexecuted is preserved by combining the file name in which it is declared\nwith the string key that was passed to the Func function. Updating an app\nwith pending function invocations should safe as long as the relevant\nfunctions have the (filename, key) combination preserved. The filename is\nparsed according to these rules:\n\n- Paths in package main are shortened to just the file name (github.com/foo/foo.go -\\\u003e foo.go)\n- Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -\\\u003e github.com/foo/bar.go)\n- Module versions are stripped (/go/pkg/mod/github.com/foo/bar@v0.0.0-20181026220418-f595d03440dc/baz.go -\\\u003e github.com/foo/bar/baz.go)\n\nThere is some inherent risk of pending function invocations being lost during\nan update that contains large changes. For example, switching from using GOPATH\nto go.mod is a large change that may inadvertently cause file paths to change.\n\nThe delay package uses the Task Queue API to create tasks that call the\nreserved application path \"/_ah/queue/go/delay\".\nThis path must not be marked as \"login: required\" in app.yaml;\nit must be marked as \"login: admin\" or have no access restriction. \n\nFunctions\n---------\n\n### func RequestHeaders\n\n func RequestHeaders(c https://pkg.go.dev/golang.org/x/net/context.https://pkg.go.dev/golang.org/x/net/context#Context) (*https://pkg.go.dev/google.golang.org/appengine/taskqueue.https://pkg.go.dev/google.golang.org/appengine/taskqueue#RequestHeaders, https://pkg.go.dev/builtin#error)\n\nRequest returns the special task-queue HTTP request headers for the current\ntask queue handler. Returns an error if called from outside a delay.Func. \n\nFunction\n--------\n\n type Function struct {\n \t// contains filtered or unexported fields\n }\n\nFunction represents a function that may have a delayed invocation. \n\n### func Func\n\n func Func(key https://pkg.go.dev/builtin#string, i interface{}) *#google_golang_org_appengine_delay_Function\n\nFunc declares a new Function. The second argument must be a function with a\nfirst argument of type context.Context.\nThis function must be called at program initialization time. That means it\nmust be called in a global variable declaration or from an init function.\nThis restriction is necessary because the instance that delays a function\ncall may not be the one that executes it. Only the code executed at program\ninitialization time is guaranteed to have been run by an instance before it\nreceives a request. \n\n### func (\\*Function) Call\n\n func (f *#google_golang_org_appengine_delay_Function) Call(c https://pkg.go.dev/golang.org/x/net/context.https://pkg.go.dev/golang.org/x/net/context#Context, args ...interface{}) https://pkg.go.dev/builtin#error\n\nCall invokes a delayed function.\nerr := f.Call(c, ...)\nis equivalent to\nt, *:= f.Task(...)*, err := taskqueue.Add(c, t, \"\") \n\n### func (\\*Function) Task\n\n func (f *#google_golang_org_appengine_delay_Function) Task(args ...interface{}) (*https://pkg.go.dev/google.golang.org/appengine/taskqueue.https://pkg.go.dev/google.golang.org/appengine/taskqueue#Task, https://pkg.go.dev/builtin#error)\n\nTask creates a Task that will invoke the function.\nIts parameters may be tweaked before adding it to a queue.\nUsers should not modify the Path or Payload fields of the returned Task."]]