pear-opstream
v1.0.1
Published
Pear operations stream base class
Readme
Opstream
Pear operations stream base class
Readable stream wrapper around an async op(params) function.
Emits status object data events, at minimum:
- zero or one
{ tag: 'error', ... }objects - logical errors fromop, not stream errors - exactly one
{ tag: 'final', ... }object
For convenience consumer counterpart library see pear-opwait.
Install
npm install pear-opstreamAPI: new Opstream(op, params, done?)
Create a new Opstream Instance.
Parameters
op: (params) => Promise<any>Async function called once when the stream eagerly reads.params: ObjectInput passed intoop.- if `params.linka is present, it is normalized at origin:
params.link = plink.normalize(params.link)
- if `params.linka is present, it is normalized at origin:
done?: () => voidOptional callback once emitted after the final chunk and stream ends.
Emitted data status objects
if
oprejects.{ tag: 'error', data: { stack, code, message, success: false, info } }finalstatus object always emitted exactly once:{ tag: 'final', data: { success, ...final } }
Custom 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 }
}License
Apache-2.0
