UNPKG

1.29 kBtext/coffeescriptView Raw
1noflo = require 'noflo'
2
3class SendNext extends noflo.Component
4 description: 'Sends next packet in buffer when receiving a bang'
5 icon: 'forward'
6
7 constructor: ->
8 @inPorts = new noflo.InPorts
9 data:
10 datatype: 'all'
11 buffered: yes
12 in:
13 datatype: 'bang'
14
15 @outPorts = new noflo.OutPorts
16 out:
17 datatype: 'all'
18 empty:
19 datatype: 'bang'
20 required: false
21
22 @inPorts.in.on 'data', =>
23 do @sendNext
24
25 sendNext: ->
26 sent = false
27 loop
28 packet = @inPorts.data.receive()
29 unless packet
30 @outPorts.empty.send true
31 @outPorts.empty.disconnect()
32 break
33 groups = []
34 switch packet.event
35 when 'begingroup'
36 @outPorts.out.beginGroup packet.payload
37 groups.push packet.payload
38 when 'data'
39 if sent
40 # Return packet to beginning of queue and abort
41 @inPorts.data.buffer.unshift packet
42 return
43 @outPorts.out.send packet.payload
44 sent = true
45 when 'endgroup'
46 @outPorts.out.endGroup()
47 groups.pop()
48 return if groups.length is 0
49 when 'disconnect'
50 @outPorts.out.disconnect()
51 return
52
53exports.getComponent = -> new SendNext