Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
control flow example
{"label":"root","blocks":[{"label":"","type":"latch","id":2,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"boolean"}],"outputs":[{"name":"true","type":"any"},{"name":"false","type":"any"}],"source":null,"position":{"x":794,"y":227}},{"label":"","type":"gate","id":4,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":426,"y":228}},{"label":"ticker","type":"delay","id":1,"inputs":[{"name":"in","value":{"data":"boo"},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":490,"y":371}},{"label":"","type":"+","id":14,"inputs":[{"name":"x","value":null,"type":"number"},{"name":"y","value":{"data":1},"type":"number"}],"outputs":[{"name":"x+y","type":"number"}],"source":null,"position":{"x":433,"y":106}},{"label":"","type":"identity","id":10,"inputs":[{"name":"in","value":{"data":0},"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":141,"y":113}},{"label":"","type":"first","id":7,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"first","type":"boolean"}],"source":null,"position":{"x":278,"y":205}},{"label":"","type":"latch","id":8,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"boolean"}],"outputs":[{"name":"true","type":"any"},{"name":"false","type":"any"}],"source":null,"position":{"x":405,"y":112}},{"label":"","type":"sink","id":23,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":939,"y":291}},{"label":"","type":"log","id":25,"inputs":[{"name":"log","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":936,"y":198}},{"label":"","type":"mod","id":27,"inputs":[{"name":"dividend","value":null,"type":"number"},{"name":"divisor","value":{"data":2},"type":"number"}],"outputs":[{"name":"remainder","type":"number"}],"source":null,"position":{"x":638,"y":71}},{"label":"","type":"==","id":31,"inputs":[{"name":"x","value":null,"type":"any"},{"name":"y","value":{"data":0},"type":"any"}],"outputs":[{"name":"x==y","type":"boolean"}],"source":null,"position":{"x":763,"y":193}}],"connections":[{"from":{"id":2,"route":0},"to":{"id":25,"route":0},"id":26},{"from":{"id":31,"route":0},"to":{"id":2,"route":1},"id":33},{"from":{"id":7,"route":0},"to":{"id":8,"route":1},"id":9},{"from":{"id":10,"route":0},"to":{"id":7,"route":0},"id":11},{"from":{"id":10,"route":0},"to":{"id":8,"route":0},"id":12},{"from":{"id":14,"route":0},"to":{"id":4,"route":0},"id":16},{"from":{"id":4,"route":0},"to":{"id":14,"route":0},"id":17},{"from":{"id":14,"route":0},"to":{"id":27,"route":0},"id":28},{"from":{"id":1,"route":0},"to":{"id":4,"route":1},"id":5},{"from":{"id":8,"route":0},"to":{"id":14,"route":0},"id":15},{"from":{"id":27,"route":0},"to":{"id":31,"route":0},"id":32},{"from":{"id":4,"route":0},"to":{"id":2,"route":0},"id":22},{"from":{"id":2,"route":1},"to":{"id":23,"route":0},"id":24}],"groups":[{"id":0,"label":"root","children":[2,4,6,14,18,23,25,34],"position":{"x":0,"y":0}},{"id":6,"label":"ticker","children":[1],"position":{"x":255,"y":271}},{"id":18,"label":"init","children":[10,7,8],"position":{"x":274,"y":78}},{"id":34,"label":"is even","children":[27,31],"position":{"x":580,"y":122}}],"sources":[],"links":[]}
@mikedewar

This comment has been minimized.

Copy link
Owner Author

mikedewar commented Nov 13, 2015

image

@mikedewar

This comment has been minimized.

Copy link
Owner Author

mikedewar commented Nov 13, 2015

This pattern presents an example of using streamtools' control functions.

  • The group called "ticker" emits a message every second
  • T "init" group emits a single 0 when the pattern is initialised.
  • That 0 flows through the + block, which adds 1 to it.
  • The incremented message waits at the gate for ticker's emission
  • the "is even" group emits true if its inbound message is true and false otherwise
  • the latch therefore controls the sinking of odd numbers and the printing of even numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.