-
Notifications
You must be signed in to change notification settings - Fork 0
Calling Functions
After defining and registering a function with a Dispatch endpoint, the next step is to dispatch work to functions.
Function calls are typically dispatched in response to a trigger or event, for example when an HTTP request is received, or for each message in a message queue.
A function call can be dispatched using the Dispatch
method on Dispatch functions, which accepts an input argument.
For example, given the following function that converts an integer to a string:
stringify := dispatch.Func("stringify", func (ctx context.Context, input int) (string, error) {
return strconv.Itoa(input), nil
})
a call to the function (stringify(11)
) could be dispatched like so:
id, err := stringify.Dispatch(context.Background(), 11)
This submits a function call to the Dispatch cloud service, which coordinates the execution of the function. The function is executed asynchronously.
The Dispatch
method returns a globally unique identifier for the function call for observability purposes.
If the function call could not be dispatched, an error is returned instead.
See how to compose functions into workflows.