Function types
This page lists every PubNub Function trigger type and its exact execution semantics. For what each type is used for and why, see Functions overview.
Trigger types
| Trigger type | Execution mode | Fires on | Returns a timetoken to the publisher? |
|---|---|---|---|
| Before Publish or Fire | Synchronous | A published message, before delivery | Yes (delivery is held until the Function resolves) |
| Before Publish File | Synchronous | A file message, before delivery | Yes |
| Before Signal | Synchronous | A signal, before delivery | N/A (signals don't return a timetoken) |
| After Publish or Fire | Asynchronous | A copy of a published message, after delivery | No (the timetoken was already returned before the Function ran) |
| After Publish File | Asynchronous | A copy of a file message, after delivery | No |
| After Signal | Asynchronous | A copy of a signal, after delivery | No |
| After Presence | Asynchronous | A presence event (join, leave, timeout, state-change, interval) | N/A |
| On Interval | Asynchronous | A configured repeating schedule, not a message event | N/A |
| On Request | Synchronous | An inbound HTTP request to the Function's configured path | N/A (returns an HTTP response instead) |
| Subscribe on Interval | Asynchronous | Combines subscribe traffic with interval timing | N/A |
Subscribe on Interval is a gated trigger type. See On Interval for the access note.
Choosing synchronous or asynchronous
Use a synchronous trigger if the Function needs to do any of the following:
- Block a message
- Change a message or its payload
- Change message metadata
- Re-route a message to a different channel
Use an asynchronous trigger for everything else.
Both a synchronous and an asynchronous trigger can attach to the same channel. For example, a synchronous trigger can transform a message while an asynchronous trigger forwards it to an external system.
Network I/O in a synchronous Function extends the time the publisher waits for a response. See xhr for the module's latency implications.
After Presence event values
| Event value | Fires on |
|---|---|
join | A subscriber joins the channel |
leave | A subscriber leaves the channel |
timeout | A connection drops and the subscriber isn't seen for the timeout period |
state-change | A subscriber updates channel state through the state API |
interval | An occupancy count sent at the Presence interval |
The exact state-change event signature can vary by client SDK.
Channel targeting
A Function targets one or more channels through an exact channel name or a wildcard pattern. Wildcard patterns support up to two levels, and the wildcard must be the last segment of the pattern. See Targeting channels for the full wildcard grammar and examples.
Related reference
- Functions overview. Read the conceptual model for trigger types, synchronous and asynchronous execution, and channel targeting.
- Request and response objects. Look up the exact fields on the request, response, and event objects available to each trigger type.
- Modules and libraries. Look up the built-in module API available inside a Function.
- API limits. Look up the numeric limits that apply to Function execution, deployment, and storage.