Skip to content

Commit

Permalink
WirePattern sending defaults to params automatically, refs #212, #217,
Browse files Browse the repository at this point in the history
  • Loading branch information
trustmaster committed Jul 15, 2014
1 parent d16c311 commit 91e3bc2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 0 additions & 6 deletions spec/Helpers.coffee
Expand Up @@ -753,8 +753,6 @@ describe 'Component traits', ->
d1.disconnect()
d2.send 123
d2.disconnect()
p3.send() # Send default
p3.disconnect()
p1.send 'req'
p1.disconnect()
# the handler should be triggered here
Expand Down Expand Up @@ -803,8 +801,6 @@ describe 'Component traits', ->
d1.disconnect()
d2.send 123
d2.disconnect()
p3.send() # Send default
p3.disconnect()
p1.send 'req'
p1.disconnect()
# the handler should be triggered here
Expand Down Expand Up @@ -920,7 +916,6 @@ describe 'Component traits', ->
chai.expect(c.invCount).to.equal 3
done()

whn.send() # Send defaults
line.send 'op'
rpt.send 10
line.disconnect()
Expand All @@ -937,7 +932,6 @@ describe 'Component traits', ->

# this flushes the earlier stuff


it 'should be able to postpone and retry after timeout', (done) ->
c.invCount = 0
res.once 'data', (data) ->
Expand Down
20 changes: 20 additions & 0 deletions src/lib/Helpers.coffee
Expand Up @@ -3,6 +3,7 @@
# NoFlo may be freely distributed under the MIT license
StreamSender = require('./Streams').StreamSender
StreamReceiver = require('./Streams').StreamReceiver
InternalSocket = require './InternalSocket'

# MapComponent maps a single inport to a single outport, forwarding all
# groups from in to out and calling `func` on each incoming packet
Expand Down Expand Up @@ -180,6 +181,19 @@ exports.WirePattern = (component, config, proc) ->
component.params = {}
component.requiredParams = []
component.completeParams = []
component.defaultedParams = []
component.defaultsSent = false

sendDefaultParams = ->
if not component.defaultsSent and component.defaultedParams.length > 0
for param in component.defaultedParams
tempSocket = InternalSocket.createSocket()
component.inPorts[param].attach tempSocket
tempSocket.send()
tempSocket.disconnect()
component.inPorts[param].detach tempSocket
component.defaultsSent = true

resumeTaskQ = ->
if component.completeParams.length is component.requiredParams.length and
component.taskQ.length > 0
Expand All @@ -193,6 +207,7 @@ exports.WirePattern = (component, config, proc) ->
unless component.inPorts[port]
throw new Error "no inPort named '#{port}'"
component.requiredParams.push port if component.inPorts[port].isRequired()
component.defaultedParams.push port if component.inPorts[port].hasDefault()
for port in config.params
do (port) ->
inPort = component.inPorts[port]
Expand Down Expand Up @@ -345,6 +360,9 @@ exports.WirePattern = (component, config, proc) ->
if typeof component.beforeProcess is 'function'
component.beforeProcess outs

# Sending defaults if not sent already
sendDefaultParams()

# Group forwarding
if outPorts.length is 1
outs.beginGroup g for g in groups if config.forwardGroups
Expand Down Expand Up @@ -387,6 +405,8 @@ exports.WirePattern = (component, config, proc) ->
component.taskQ = []
component.params = {}
component.completeParams = []
component.defaultedParams = []
component.defaultsSent = false

# Make it chainable or usable at the end of getComponent()
return component
Expand Down

0 comments on commit 91e3bc2

Please sign in to comment.