noflo-core
Version:
NoFlo Essentials
48 lines (41 loc) • 1.15 kB
text/coffeescript
noflo = require 'noflo'
class SendNext extends noflo.Component
description: 'Sends next packet in buffer when receiving a bang'
icon: 'forward'
constructor: ->
= new noflo.InPorts
data:
datatype: 'all'
buffered: yes
in:
datatype: 'bang'
= new noflo.OutPorts
out:
datatype: 'all'
.in.on 'data', =>
do
sendNext: ->
sent = false
loop
packet = .data.receive()
break unless packet
groups = []
switch packet.event
when 'begingroup'
.out.beginGroup packet.payload
groups.push packet.payload
when 'data'
if sent
# Return packet to beginning of queue and abort
.data.buffer.unshift packet
return
.out.send packet.payload
sent = true
when 'endgroup'
.out.endGroup()
groups.pop()
return if groups.length is 0
when 'disconnect'
.out.disconnect()
return
exports.getComponent = -> new SendNext