Skip to content

Commit

Permalink
Component for reading packet groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed May 16, 2012
1 parent 91a4eed commit 9ea32f1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/components/ReadGroup.coffee
@@ -0,0 +1,20 @@
noflo = require 'noflo'

class ReadGroup extends noflo.Component
constructor: ->
@groups = []

@inPorts =
in: new noflo.ArrayPort
@outPorts =
out: new noflo.Port

@inPorts.in.on 'begingroup', (group) =>
@groups.push group
@inPorts.in.on 'data', =>
return unless @groups.length
@outPorts.out.send @groups.join ':'
@inPorts.in.on 'endgroup', =>
@groups.pop()

exports.getComponent = -> new ReadGroup
29 changes: 29 additions & 0 deletions test/ReadGroup.coffee
@@ -0,0 +1,29 @@
readenv = require "../src/components/ReadGroup"
socket = require "../src/lib/InternalSocket"

setupComponent = ->
c = readenv.getComponent()
ins = socket.createSocket()
out = socket.createSocket()
c.inPorts.in.attach ins
c.outPorts.out.attach out
[c, ins, out]

exports['test reading a group'] = (test) ->
test.expect 1
[c, ins, out] = setupComponent()
out.once 'data', (data) ->
test.equal data, 'foo'
test.done()
ins.beginGroup 'foo'
ins.send 'hello'

exports['test reading a subgroup'] = (test) ->
test.expect 1
[c, ins, out] = setupComponent()
out.once 'data', (data) ->
test.equal data, 'foo:bar'
test.done()
ins.beginGroup 'foo'
ins.beginGroup 'bar'
ins.send 'hello'

0 comments on commit 9ea32f1

Please sign in to comment.