Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
shmoop207 committed Apr 5, 2020
1 parent 0929939 commit 6ddfec8
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 60 deletions.
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,47 @@ let [result,result2] = await Promise.all([promise1,promise2])
- `concurrency` - max concurrent running promises default `1`
- `timeout` - max wait time for promise to settle on the promise wil be rejected default `null`
- `autoStart` - start running promises as the added default `true`
- `expire` - max time the job can wait in the queue is when passed the job will be removed without execution of the promise
- `timespan` - time frame in milliseconds of concurrency jobs

```javascript

const queue = new Queue({
concurrency:2,
concurrency: 2,
timeout: 1000,
autoStart :false
autoStart: false,
timespan:60000
});

```

#### Add
add promise to queue with given Promise-returning/async function
#### add(fn,[options])
add job to queue with given Promise-returning/async function
##### options:
- timeout - override queue timeout for this promise
- priority - promise priority in the queue greater priority will be scheduled first
- `timeout` - override queue timeout for this job.
- `priority` - job priority in the queue greater priority will be scheduled first.
- `expire` - max time the job can wait in the queue before it removed.

returns promise when the origin promise settled;

```javascript
const queue = new Queue();

await queue.add(async ()=>await "something",{timeout:1000,priority:100})
```
await queue.add(async ()=>await "something",{timeout:1000,priority:100});

await queue.add(()=>Promise.resolve(),{expire:60000});

```

#### start
#### start()
Start (or resume) executing enqueued promises
#### stop
#### stop()
stop queue execution

#### onDrain
#### onDrain()
Returns a promise that settles when the queue becomes empty

#### onIdle
#### onIdle()
Returns a promise that settles when the queue becomes empty, and all promises have completed
```javascript

Expand All @@ -74,7 +81,7 @@ const queue = new Queue();

await queue.onIdle();
```
#### clear
#### clear()
clear the queue

#### size
Expand All @@ -95,6 +102,12 @@ return true if queue is empty
#### isIdle
return true if queue is empty and no running promises

#### has(fn)
return true if given fn exists in queue;

#### remove(fn)
removes given fn from queue

### Events

#### onDrainEvent
Expand Down
2 changes: 2 additions & 0 deletions lib/IOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export interface IOptions {
concurrency?: number
timeout?: number
expire?: number
timespan?: number
autoStart?: boolean;
}
2 changes: 2 additions & 0 deletions lib/IQueueItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export interface IQueueItem<T> {
reject: (reason?: any) => any,
priority: number,
timeout: number
expire: number
insertTime: number
}
2 changes: 2 additions & 0 deletions lib/defautls.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/defautls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import {IOptions} from "./IOptions";
export let OptionsDefaults: Partial<IOptions> = {
concurrency: 1,
timeout: 0,
expire: 0,
timespan: 0,
autoStart: true
};
74 changes: 55 additions & 19 deletions lib/queue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ddfec8

Please sign in to comment.