Comparing version 1.7.0 to 1.8.0
@@ -1,11 +0,11 @@ | ||
declare function fastq<T>(context: T, worker: fastq.worker<T>, concurrency: number): fastq.queue | ||
declare function fastq<T>(worker: fastq.worker<T>, concurrency: number): fastq.queue | ||
declare function fastq<C, T = any, R = any>(context: C, worker: fastq.worker<C, T, R>, concurrency: number): fastq.queue<T, R> | ||
declare function fastq<C, T = any, R = any>(worker: fastq.worker<C, T, R>, concurrency: number): fastq.queue<T, R> | ||
declare namespace fastq { | ||
type worker<T> = (this: T, arg: any, cb: () => void) => void | ||
type done = (err: Error, result: any) => void | ||
type worker<C, T = any, R = any> = (this: C, task: T, cb: fastq.done<R>) => void | ||
type done<R = any> = (err: Error | null, result?: R) => void | ||
interface queue { | ||
push(task: any, done: done): void | ||
unshift(task: any, done: done): void | ||
interface queue<T = any, R = any> { | ||
push(task: T, done: done<R>): void | ||
unshift(task: T, done: done<R>): void | ||
pause(): any | ||
@@ -15,2 +15,3 @@ resume(): any | ||
length(): number | ||
getQueue(): T[] | ||
kill(): any | ||
@@ -25,2 +26,2 @@ killAndDrain(): any | ||
export = fastq | ||
export = fastq |
{ | ||
"name": "fastq", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "Fast, in memory work queue", | ||
@@ -5,0 +5,0 @@ "main": "queue.js", |
import * as fastq from '../' | ||
const queue = fastq({ hello: 'world' }, worker, 1) | ||
// Basic example | ||
queue.push(42, (err, done) => { | ||
const queue = fastq(worker, 1) | ||
queue.push('world', (err, result) => { | ||
if (err) throw err | ||
console.log('the result is', done) | ||
console.log('the result is', result) | ||
}) | ||
@@ -16,2 +18,4 @@ | ||
console.log('the queue tasks are', queue.getQueue()) | ||
queue.idle() | ||
@@ -31,9 +35,31 @@ | ||
queue.unshift(42, (err, done) => { | ||
queue.unshift('world', (err, result) => { | ||
if (err) throw err | ||
console.log('the result is', result) | ||
}) | ||
function worker(task: any, cb: fastq.done) { | ||
cb(null, 'hello ' + task) | ||
} | ||
// Generics example | ||
interface GenericsContext { | ||
base: number; | ||
} | ||
const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1) | ||
genericsQueue.push(7, (err, done) => { | ||
if (err) throw err | ||
console.log('the result is', done) | ||
}) | ||
function worker(arg: any, cb: any) { | ||
cb(null, 42 * 2) | ||
genericsQueue.unshift(7, (err, done) => { | ||
if (err) throw err | ||
console.log('the result is', done) | ||
}) | ||
function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) { | ||
cb(null, 'the meaning of life is ' + (this.base * task)) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25946
695