Skip to content

Commit 28b722f

Browse files
Merge pull request #5380 from dtran320/patch-1
Add notes on usage in serverless environments
2 parents 4e81ee8 + 85ca04c commit 28b722f

File tree

1 file changed

+12
-0
lines changed
  • src/connections/sources/catalog/libraries/server/node

1 file changed

+12
-0
lines changed

src/connections/sources/catalog/libraries/server/node/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ Setting | Details
288288
289289
See the complete `AnalyticsSettings` interface [here](https://github.com/segmentio/analytics-next/blob/master/packages/node/src/app/settings.ts){:target="_blank"}.
290290
291+
## Usage in serverless environments
292+
293+
When calling `.track` within functions in serverless runtime environments, wrap the call in a `Promise` and `await` it to avoid having the runtime exit or freeze:
294+
295+
```js
296+
await new Promise((resolve) =>
297+
analytics().track({ ... }, resolve)
298+
)
299+
```
300+
301+
See the complete documentation on [Usage in AWS Lambda](https://github.com/segmentio/analytics-next/blob/master/packages/node/README.md#usage-in-aws-lambda){:target="_blank"}, [Usage in Vercel Edge Functions](https://github.com/segmentio/analytics-next/blob/master/packages/node/README.md#usage-in-vercel-edge-functions){:target="_blank"}, and [Usage in Cloudflare Workers](https://github.com/segmentio/analytics-next/blob/master/packages/node/README.md#usage-in-cloudflare-workers){:target="_blank"}
302+
291303
## Graceful shutdown
292304
Avoid losing events after shutting down your console. Call `.closeAndFlush()` to stop collecting new events and flush all existing events. If a callback on an event call is included, this also waits for all callbacks to be called, and any of their subsequent promises to be resolved.
293305

0 commit comments

Comments
 (0)