Skip to content

Instantly share code, notes, and snippets.

@mikedewar
Last active November 14, 2015 00:12
Show Gist options
  • Save mikedewar/b0fddd6e1e66a7887f2d to your computer and use it in GitHub Desktop.
Save mikedewar/b0fddd6e1e66a7887f2d to your computer and use it in GitHub Desktop.
a simple blocking example
{"label":"root","blocks":[{"label":"","type":"delay","id":13,"inputs":[{"name":"in","value":{"data":2},"type":"any"},{"name":"duration","value":{"data":"2s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":226,"y":272}},{"label":"","type":"log","id":16,"inputs":[{"name":"log","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":777,"y":190}},{"label":"","type":"delay","id":3,"inputs":[{"name":"in","value":{"data":1},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":221,"y":159}},{"label":"","type":"set","id":22,"inputs":[{"name":"key","value":{"data":"top"},"type":"string"},{"name":"value","value":null,"type":"any"}],"outputs":[{"name":"object","type":"object"}],"source":null,"position":{"x":474,"y":146}},{"label":"","type":"set","id":23,"inputs":[{"name":"key","value":{"data":"bottom"},"type":"string"},{"name":"value","value":null,"type":"any"}],"outputs":[{"name":"object","type":"object"}],"source":null,"position":{"x":477,"y":258}},{"label":"","type":"merge","id":26,"inputs":[{"name":"in","value":null,"type":"object"},{"name":"in","value":null,"type":"object"}],"outputs":[{"name":"out","type":"object"}],"source":null,"position":{"x":651,"y":190}}],"connections":[{"from":{"id":23,"route":0},"to":{"id":26,"route":1},"id":28},{"from":{"id":22,"route":0},"to":{"id":26,"route":0},"id":27},{"from":{"id":13,"route":0},"to":{"id":23,"route":1},"id":29},{"from":{"id":3,"route":0},"to":{"id":22,"route":1},"id":30},{"from":{"id":26,"route":0},"to":{"id":16,"route":0},"id":31}],"groups":[{"id":0,"label":"root","children":[13,16,3,22,23,26],"position":{"x":0,"y":0}}],"sources":[],"links":[]}
@mikedewar
Copy link
Author

image

@mikedewar
Copy link
Author

This pattern demonstrates blocking behaviour and the idea of backpressure.

It has two paths - the top emits messages at 1 message per second and the bottom emits messages at 1 message every 2 seconds. The messages are set to keys and merged, before being printed. This pattern emits 1 message every 2 seconds, as the merge operation has to wait for the slower path to satisfy before releasing the pressure on the top path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment