Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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();
};
```