---
source_url: https://www.pubnub.com/docs/serverless-sdk/function-types
title: Function types
updated_at: 2026-09-30T07:20:08.000Z
---

# Function types

## Documentation index

To discover more PubNub resources:

1. Fetch [PubNub's llms.txt](https://www.pubnub.com/llms-full.txt) for a list of available pages in Markdown format.
2. Identify relevant URLs from that index.
3. Fetch the target pages.

Do not assume a path exists, always check the index first.

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](https://www.pubnub.com/docs/message-processing/serverless/overview.md).

## 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](https://www.pubnub.com/docs/message-processing/serverless/overview.md#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](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/xhr.md) 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](https://www.pubnub.com/docs/message-processing/serverless/overview.md#targeting-channels) for the full wildcard grammar and examples.

## Related reference

* [Functions overview](https://www.pubnub.com/docs/message-processing/serverless/overview.md). Read the conceptual model for trigger types, synchronous and asynchronous execution, and channel targeting.
* [Request and response objects](https://www.pubnub.com/docs/serverless-sdk/request-response-objects.md). Look up the exact fields on the request, response, and event objects available to each trigger type.
* [Modules and libraries](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/overview.md). Look up the built-in module API available inside a Function.
* [API limits](https://www.pubnub.com/docs/serverless-sdk/api-limits.md). Look up the numeric limits that apply to Function execution, deployment, and storage.

Last updated at: 2026-09-30T07:20:08.000Z
