noflo-core
Version:
NoFlo Essentials
51 lines (43 loc) • 1.18 kB
text/coffeescript
noflo = require 'noflo'
class RunInterval extends noflo.Component
description: 'Send a packet at the given interval'
icon: 'clock-o'
constructor: ->
= null
= null
= new noflo.InPorts
interval:
datatype: 'number'
description: 'Interval at which output packets are emitted (ms)'
start:
datatype: 'bang'
description: 'Start the emission'
stop:
datatype: 'bang'
description: 'Stop the emission'
=
out:
datatype: 'bang'
.interval.on 'data', (interval) =>
= interval
# Restart if currently running
if ?
clearInterval
do
.start.on 'data', =>
clearInterval if ?
.out.connect()
do
.stop.on 'data', =>
return unless
clearInterval
= null
.out.disconnect()
start: ->
out = .out
= setInterval ->
out.send true
,
shutdown: ->
clearInterval if ?
exports.getComponent = -> new RunInterval