Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/alexandershushunov/invoke-in-sequence-only-the-first-and-last


https://github.com/alexandershushunov/invoke-in-sequence-only-the-first-and-last

Last synced: 23 days ago
JSON representation

Awesome Lists containing this project

README

        

### Invoke In Sequence Only The First And Last

This high-order function wraps an asynchronous function to
ensure controlled execution. When the wrapped function
is invoked, it starts executing immediately if it's the
first call. However, if the function is called multiple
times before the first execution completes, only the last
call will be executed once the first execution finishes.
This mechanism ensures that no parallel executions occur,
and redundant calls are ignored until the initial
execution is complete.

```typescript
async function base(params): Promise {
...
}
const wrapped = invokeInSequenceOnlyTheFirstAndLast(base)
```

![diagram.png](diagram.png)