Skip to content

Instantly share code, notes, and snippets.

@bergie
Created February 15, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bergie/4c3d7ca6207c14adacc27b0caa04db16 to your computer and use it in GitHub Desktop.
Save bergie/4c3d7ca6207c14adacc27b0caa04db16 to your computer and use it in GitHub Desktop.
Bsync.coffee
noflo = require 'noflo'
window.bsyncs = []
class Bsync
constructor: (@request,@waitfor,@block,@callback) ->
exports.getComponent = ->
c = new noflo.Component
c.description = 'bsync'
c.icon = 'share'
c.inPorts.add 'request',
datatype: 'string'
default: ""
control: true
c.inPorts.add 'waitfor',
datatype: 'string'
control: true
default: ""
c.inPorts.add 'block',
datatype: 'string'
control: true
default: ""
c.inPorts.add 'signal',
datatype: 'bang'
c.outPorts.add 'element',
datatype: 'object'
c.process (input, output) ->
return unless input.hasStream 'signal'
return if input.attached('request').length and not input.hasData 'request'
return if input.attached('waitfor').length and not input.hasData 'waitfor'
return if input.attached('block').length and not input.hasData 'block'
request = input.getData 'request'
wait = input.getData 'waitfor'
block = input.getData 'block'
signal = input.get 'signal'
scope = ""
if signal != null
scope = signal.scope
if scope is "skip"
console.log("**************skipping bsync**************")
output.sendDone
element:scope
return
callback = (element) ->
console.log("Callback called with element:", element)
s = scope
if element is scope
console.log("Need to break upon event")
s = "skip"
totalBsyncs--
o = new noflo.IP 'data', element,
scope: s
output.send
element:o
if scope != null and scope != ""
wait = scope
bsync = new Bsync(request,wait,block,callback)
console.log("Added new bsync object ", bsync)
window.bsyncs.push(bsync)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment