Pear operations stream base class
Readable stream wrapper around an async op(params) function.
Emits status object data events, at minimum:
{ tag: 'error', ... } objects - logical errors from op, not stream errors{ tag: 'final', ... } objectFor convenience consumer counterpart library see pear-opwait.
npm install pear-opstream
new Opstream(op, params, done?)Create a new Opstream Instance.
op: (params) => Promise<any>
Async function called once when the stream eagerly reads.
params: Object
Input passed into op.
params.link = plink.normalize(params.link)
done?: () => void
Optional callback once emitted after the final chunk and stream ends.
if op rejects.
{
tag: 'error',
data: { stack, code, message, success: false, info }
}
final status object always emitted exactly once:
{
tag: 'final',
data: { success, ...final }
}
The { tag: 'final', ... } status object merges with instance.final.
Set this.final in subclass to declare final return value of opstream.
this.final = { result: 42 }
final chunk:
{
tag: 'final',
data: { success: true, result: 42 }
}
Apache-2.0