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 typeExecution modeFires onReturns a timetoken to the publisher?
Before Publish or FireSynchronousA published message, before deliveryYes (delivery is held until the Function resolves)
Before Publish FileSynchronousA file message, before deliveryYes
Before SignalSynchronousA signal, before deliveryN/A (signals don't return a timetoken)
After Publish or FireAsynchronousA copy of a published message, after deliveryNo (the timetoken was already returned before the Function ran)
After Publish FileAsynchronousA copy of a file message, after deliveryNo
After SignalAsynchronousA copy of a signal, after deliveryNo
After PresenceAsynchronousA presence event (join, leave, timeout, state-change, interval)N/A
On IntervalAsynchronousA configured repeating schedule, not a message eventN/A
On RequestSynchronousAn inbound HTTP request to the Function's configured pathN/A (returns an HTTP response instead)
Subscribe on IntervalAsynchronousCombines subscribe traffic with interval timingN/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 valueFires on
joinA subscriber joins the channel
leaveA subscriber leaves the channel
timeoutA connection drops and the subscriber isn't seen for the timeout period
state-changeA subscriber updates channel state through the state API
intervalAn 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.

  • 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.

Was this page useful?

Last updated on