Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from kenhkan/repeat_async

Like 'Repeat', except asynchronous; mainly for databases and HTTP req/re...
  • Loading branch information...
commit 5f4fcfa7d0808338a8add3bdcde8c5a8be0d9889 2 parents b336a55 + 4ebf4c5
@bergie bergie authored
Showing with 44 additions and 0 deletions.
  1. +44 −0 src/components/RepeatAsync.coffee
View
44 src/components/RepeatAsync.coffee
@@ -0,0 +1,44 @@
+noflo = require("noflo")
+util = require("util")
+
+
+
+class RepeatAsync extends noflo.Component
+
+ description: "Like 'Repeat', except repeat on next tick"
+
+ constructor: ->
+ @groups = []
+
+ # Ports
+ @inPorts =
+ in: new noflo.Port()
+ @outPorts =
+ out: new noflo.Port()
+
+ # Forward on next tick
+ @inPorts.in.on "begingroup", (group) =>
+ @groups.push(group)
+
+ @inPorts.in.on "data", (data) =>
+ groups = @groups
+
+ later = () =>
+ for group in groups
+ @outPorts.out.beginGroup(group)
+
+ @outPorts.out.send(data)
+
+ for group in groups
+ @outPorts.out.endGroup()
+
+ @outPorts.out.disconnect()
+
+ setTimeout(later, 0)
+
+ @inPorts.in.on "disconnect", () =>
+ @groups = []
+
+
+
+exports.getComponent = () -> new RepeatAsync
Please sign in to comment.
Something went wrong with that request. Please try again.