Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bubblydoo/wait-until-aws-lambda
Fake `waitUntil` for AWS Lambda
https://github.com/bubblydoo/wait-until-aws-lambda
Last synced: 8 days ago
JSON representation
Fake `waitUntil` for AWS Lambda
- Host: GitHub
- URL: https://github.com/bubblydoo/wait-until-aws-lambda
- Owner: bubblydoo
- Created: 2022-12-18T12:05:02.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-16T07:55:46.000Z (over 1 year ago)
- Last Synced: 2024-12-24T21:33:53.908Z (15 days ago)
- Language: TypeScript
- Size: 36.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `waitUntil` for AWS Lambda
Fake `waitUntil` in AWS Lambda and other platforms that don't support it.
```js
import { waitUntilHandler, waitUntil } from 'wait-until-aws-lambda';const delay = (time) => new Promise(res => setTimeout(res, time));
export const handler = waitUntilHandler(async (event, context) => {
waitUntil(delay(1000));return 'hello world';
});
```The callback will be delayed until the promises have finished.
### Motivation
We're migrating to Cloudflare Workers, partly because `waitUntil` is available there. With this library we can have a common API between Workers and Lambdas.
### Caveat
The `waitUntilHandler` only supports async handlers (which return promises).
### Other platforms
```js
import { WaitUntilList } from 'wait-until-aws-lambda';let waitUntilList = new WaitUntilList();
export const doStuff = async () => {
const waitUntil = waitUntilList.waitUntil;
functionThatCanCallWaitUntil(waitUntil);
await waitUntilList.waitUntilFinished();
waitUntilList = new WaitUntilList();
};
```