Skip to content

Commit

Permalink
Merge pull request #29 from defer-run/concurrency-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
charlypoly authored Feb 25, 2023
2 parents 1d21fa9 + ece6604 commit 964affd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
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 @@ -52,11 +52,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 interface Defer {

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

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

0 comments on commit 964affd

Please sign in to comment.