Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concurrency option #29

Merged
merged 4 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/cyan-cameras-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@defer/client": major
---

Add concurrency limit option.

```js
import { defer } from "@defer.run/client";

async function oneByOne() {
// do something...
}

export default defer(oneByOne, { concurrency: 1 });
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@defer.run/client",
"name": "@defer/client",
"version": "0.5.0",
"description": "Zero infrastructure NodeJS background jobs",
"main": "dist/cjs/index.js",
Expand Down
54 changes: 54 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,64 @@ export type DeferRetFnParameters<

export type RetryNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;

export type Concurrency =
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31
| 32
| 33
| 34
| 35
| 36
| 37
| 38
| 39
| 40
| 41
| 42
| 43
| 44
| 45
| 46
| 47
| 48
| 49
| 50;

export interface HasDeferMetadata {
__metadata: {
version: number;
cron?: string;
retry?: RetryNumber;
concurrency?: Concurrency;
};
}

Expand Down Expand Up @@ -92,6 +145,7 @@ export const isDeferExecution = (obj: any): obj is DeferExecuteResponse =>

export interface DeferOptions {
retry?: boolean | RetryNumber;
concurrency?: Concurrency;
}

export const defer: Defer = (fn, options) => {
Expand Down