PPG's Promise Generator Library
var Queue = Channel;var queue = 5; // buffer capacity 5var queueWithUnlimitedCapacity = ; // unlimited buffer capacity// not recommended
Getting current buffer size
Check if buffer is full or empty
A channel is essentially a queue with 0 capacity. Every put() only resolves when get() is called, and vise versa.
Consider the case where multiple asynchronous functions that can be run concurrently need to be run on a number of inputs to complete a task.
If these asynchronous functions take different times to complete, the total time will be determined by the slowest function.
Instead of running all of the functions on a single input concurrently, a pipeline runs all of the functions on the same input sequentially, and different inputs concurrently. This has several significant advantages compared to the method above.
- Each function only waits on the previous function with the help of buffers.
- Multiple instances of the same function can be run to "speed up" slow ones.
- Even if the functions must be run sequentially, pipeline can also provide concurrency.
var Pipeline = Pipeline;var pipeline = ;
Adding a generator
Adding a plain old function that returns promises
Setting minWorkers and maxWorkers. These controls the minimum and maximum number of concurrent invocation of your process
These have the same effect.
Catching the error.
A Helper Function
A helper function that converts an array of functions/generator into a pipeline
var pipelinefy = pipelinefy;var pipeline =;// use pipeline
npm run pipeline-benchmark
A function to select available channels and queues. It mimics the behavior of the select statement in Go, except that it can only select reading.
This is an example that produces the first 10 elements in the Fibonacci sequence.
"use strict";var Queue Channel select = ;var co = ;var c =next =quit = ;;;;
readers-writer-lock-example.js is another example that implements a readers-writer lock using channels and select.