GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing trigger.dev — Wait for token - Trigger.dev Waitpoint tokens pause task runs until you complete the token. They’re commonly used for approval workflows and other scenarios where you need to wait for external confirmation, such as human-in-the-loop processes.
You can complete a token using the SDK or by making a POST request to the token’s URL.
If you’re waiting for data from an input stream, use
inputStream.wait() instead — it uses
waitpoint tokens internally but provides a simpler API with full type safety from your stream
definition.UsageTo get started using wait tokens, you need to first create a token using thewait.createToken function:
wait.forToken function:
wait.completeToken function:
Completing from the browserThepublicAccessToken returned by wait.createToken() is scoped to that specific waitpoint and intended for client-side completion. The completion endpoint has CORS enabled, so you can call it directly from client-side code without proxying through your backend.
1 Create the token in your backend 2 Complete the token from the browser Completing via webhook callbackThe token.url webhook callback URL is designed for server-to-server use and does not have
CORS headers. Don’t call it from the browser, use the Completing from the
browser pattern instead.url it returns. This is an HTTP callback:
wait.createTokenCreate a waitpoint token.optionsThecreateToken function accepts an object with the following properties:
string The maximum amount of time to wait for the token to be completed. If omitted, the token has no timeout. Accepts a duration string like "30s" or "4w", or a Date.string An idempotency key for the token. If provided, the token will be completed with the same payload
if the same idempotency key is used again. string The time to live for the idempotency key. If omitted, the key does not expire. string[] Tags to attach to the token. Tags can be used to filter waitpoints in the dashboard. returnsThecreateToken function returns a token object with the following properties:
string The ID of the token. Starts with waitpoint_.string The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object {}.boolean Whether the token is cached. Will return true if the token was created with an idempotency key and
the same idempotency key was used again. string A Public Access Token that can be used to complete the token from a client-side application (or
another backend). See our Realtime docs for more details. Examplewait.completeTokenComplete a waitpoint token.parametersstring The ID of the token to complete. any The data to complete the token with. returnsThecompleteToken function returns an object with the following properties:
boolean Whether the token was completed successfully. ExampleFrom another languageYou can complete a token using a raw HTTP request or from another language.wait.forTokenWait for a token to be completed.parametersstring | { id: string } The token to wait for. returnsTheforToken function returns a result object with the following properties:
boolean Whether the token was completed successfully. any If ok is true, this will be the output of the token.Error If ok is false, this will be the error that occurred. The only error that can occur is a
timeout error.unwrap()We provide a handy.unwrap() method that will throw an error if the result is not ok. This means your happy path is a lot cleaner.
Examplewait.listTokensList all tokens for an environment.parametersThelistTokens function accepts an object with the following properties:
string | string[] Statuses to filter by. Can be one or more of: WAITING, COMPLETED, TIMED_OUT.string The idempotency key to filter by. string | string[] Tags to filter by. string The period to filter by, as a duration string such as 1h, 1d, 7d or 30d.Date | number The start date to filter by. Date | number The end date to filter by. returnsThelistTokens function returns a list of tokens that can be iterated over using a for-await-of loop.
Each token is an object with the following properties:
string The ID of the token. string The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object {}.string The status of the token. Date The date and time the token was completed. Date The date and time the token will timeout. string The idempotency key of the token. Date The date and time the idempotency key will expire. string[] The tags of the token. Date The date and time the token was created. The output of the token is not included in the list. To get the output, you need to retrieve the
token using the wait.retrieveToken function.Examplewait.retrieveTokenRetrieve a token by ID.parametersstring The ID of the token to retrieve. returnsTheretrieveToken function returns a token object with the following properties:
string The ID of the token. string The URL of the token. This is the URL you can make a POST request to in order to complete the token.The JSON body of the POST request will be used as the output of the token. If there’s no body the output will be an empty object {}.string The status of the token. Date The date and time the token was completed. Date The date and time the token will timeout. string The idempotency key of the token. Date The date and time the idempotency key will expire. string[] The tags of the token. Date The date and time the token was created. any The output of the token. Error The error that occurred. ExampleWait idempotencyYou can pass an idempotency key to any wait function, allowing you to skip waits if the same idempotency key is used again. This can be useful if you want to skip waits when retrying a task, for example:Was this page helpful? ⌘I |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |