UNPKG

823 Btext/coffeescriptView Raw
1noflo = require 'noflo'
2
3exports.getComponent = ->
4 c = new noflo.Component
5 c.description = 'Forward packet after a set delay'
6 c.icon = 'clock-o'
7
8 c.timers = []
9
10 c.inPorts.add 'in',
11 datatype: 'all'
12 description: 'Packet to be forwarded with a delay'
13 c.inPorts.add 'delay',
14 datatype: 'number'
15 description: 'How much to delay'
16 default: 500
17
18 c.outPorts.add 'out',
19 datatype: 'all'
20
21 noflo.helpers.WirePattern c,
22 in: 'in'
23 params: 'delay'
24 out: 'out'
25 forwardGroups: true
26 async: true
27 , (payload, groups, out, callback) ->
28 timer = setTimeout =>
29 out.send payload
30 do callback
31 c.timers.splice c.timers.indexOf(timer), 1
32 , c.params.delay
33 c.timers.push timer
34
35 c.shutdown = ->
36 clearTimeout timer for timer in c.timers
37 c.timers = []
38
39 c