-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
47 lines (33 loc) · 829 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var Writable = require('readable-stream').Writable
, inherits = require('inherits')
function ActStream(seneca, fixed) {
if (!(this instanceof ActStream)) {
return new ActStream(seneca, fixed)
}
this.seneca = seneca
this._fixed = fixed
Writable.call(this, {
objectMode: true,
highWaterMark: 16
})
var that = this
this._emitOnWrite = function(err) {
if (err)
that.emit('oneError', err)
that.emit('one')
var cb = that._lastCallback
if (cb) {
that._lastCallback = null
cb()
}
}
}
inherits(ActStream, Writable)
ActStream.prototype._write = function write(obj, skip, callback) {
this._lastCallback = callback
for (var key in this._fixed) {
obj[key] = this._fixed[key]
}
this.seneca.act(obj, this._emitOnWrite)
}
module.exports = ActStream