Skip to content

Commit

Permalink
Fix handling of NULL return value
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Feb 19, 2018
1 parent 145c9f3 commit 3e0862d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/AsComponent.coffee
Expand Up @@ -67,6 +67,19 @@ describe 'asComponent interface', ->
ins.post new noflo.IP 'data', 'Bar'
ins.post new noflo.IP 'data', 'Baz'
ins.post new noflo.IP 'closeBracket', 'a'
describe 'with returned NULL', ->
func = (hello) ->
return null
it 'should be possible to componentize', (done) ->
component = -> noflo.asComponent func
loader.registerComponent 'ascomponent', 'sync-one', component, done
it 'should send to OUT port', (done) ->
wrapped = noflo.asCallback 'ascomponent/sync-one',
loader: loader
wrapped 'World', (err, res) ->
return done err if err
chai.expect(res).to.be.a 'null'
done()
describe 'with a thrown exception', ->
func = (hello) ->
throw new Error "Hello #{hello}"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/AsComponent.coffee
Expand Up @@ -94,7 +94,7 @@ exports.asComponent = (func, options) ->
return

res = func.apply null, values
if typeof res is 'object' and typeof res.then is 'function'
if res and typeof res is 'object' and typeof res.then is 'function'
# Result is a Promise, resolve and handle
res.then (val) ->
output.sendDone val
Expand Down

0 comments on commit 3e0862d

Please sign in to comment.