Skip to main content

connect()

connect() constructs Pulse immediately and creates one background readiness promise. Use awaitConnection() during application startup to surface connection, permission, and index errors before accepting traffic.

Connection options

Strings must be non-empty. maxPoolSize must be a positive integer. Durations and worker counts must be finite positive numbers, except retention, retry counts, retry delays, and maxIdleTimeMS may be zero where their types allow it. Retry settings are rejected when their largest computed delay falls outside MongoDB’s supported date range. Pulse sets the MongoDB driver’s maxPoolSize to 1 instead of its default of 100, explicitly keeps minPoolSize at 0, and closes application connections after 30 idle seconds. The pool socket is used only for short coordination operations; callbacks do not retain it and can still run concurrently. The limit applies to application connections in each server pool. The driver also opens topology-monitoring connections that are not counted by maxPoolSize.
changeStreams has been removed and cannot be enabled or disabled. Pulse always uses polling. Remove the field from existing JavaScript and TypeScript configurations; providing it, even as changeStreams: 'disabled', makes connect() fail immediately with a PulseConfigurationError.

pulse.awaitConnection()

Resolves after the MongoDB client connects, the database is selected, and collections and indexes are ready. Workers start only after successful initialization. publish(), subscribe(), and subscribeBatch() call it internally.

pulse.publish()

Returns:
The event _id is a UUIDv7 string. Pulse never uses MongoDB ObjectId for its own documents.

pulse.subscribe()

Subscription options

The handler can return void or Promise<void>:
PulseReceivedEvent contains every published event field plus consumerGroup and the one-based attempt number. The returned subscription contains the resolved options, including the winning configVersion, and an idempotent asynchronous unsubscribe() method.

pulse.subscribeBatch()

The handler receives an ordered array and can return void or Promise<void>:
It accepts all ordinary subscription options and requires batchSize, a positive integer with no library-defined maximum. The configured size is a maximum. Pulse immediately executes a partial batch when fewer events are available; it does not add a batching timer. One array invocation consumes one worker and one maxConcurrency slot. Retry, fencing, heartbeat, and acknowledgement apply to the complete array. Batch materialization atomically inserts the delivery and advances its discovery cursor in a MongoDB transaction, so this API requires a replica set, sharded cluster, or Atlas.

pulse.getSubscriptions()

Returns the subscriptions registered in this process. It does not query durable subscriptions created by other replicas.

pulse.close()

Stops coordinator and worker execution, wakes sleepers, waits for background work to settle, and closes the MongoDB client. Repeated calls return the same close promise. When called and awaited from inside a handler, shutdown starts but that call returns before the shared promise so the current worker cannot deadlock waiting for itself. A call from outside the handler can await complete shutdown.

Exported errors

Collections

The names use collectionPrefix, which defaults to orionjs.pulse: Every Pulse-created _id, lock owner, and fencing token is a UUIDv7 string.

Automatically managed indexes

Pulse creates missing indexes and validates named indexes on every connection. It never drops an index automatically.

Events

Subscriptions

Deliveries

Full typed example