Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
streamtools counter
{"label":"root","blocks":[{"label":"","type":"latch","id":1,"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":358,"y":348}},{"label":"","type":"first","id":2,"inputs":[{"name":"in","value":null,"type":"any"}],"outputs":[{"name":"first","type":"boolean"}],"source":null,"position":{"x":249,"y":417}},{"label":"","type":"identity","id":4,"inputs":[{"name":"in","value":{"data":0},"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":147,"y":320}},{"label":"","type":"delay","id":10,"inputs":[{"name":"in","value":{"data":true},"type":"any"},{"name":"duration","value":{"data":"1s"},"type":"string"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":367,"y":544}},{"label":"","type":"gate","id":11,"inputs":[{"name":"in","value":null,"type":"any"},{"name":"ctrl","value":null,"type":"any"}],"outputs":[{"name":"out","type":"any"}],"source":null,"position":{"x":551,"y":493}},{"label":"","type":"+","id":13,"inputs":[{"name":"x","value":null,"type":"number"},{"name":"y","value":{"data":1},"type":"number"}],"outputs":[{"name":"x+y","type":"number"}],"source":null,"position":{"x":552,"y":379}},{"label":"","type":"log","id":17,"inputs":[{"name":"log","value":null,"type":"any"}],"outputs":[],"source":null,"position":{"x":704,"y":332}}],"connections":[{"from":{"id":2,"route":0},"to":{"id":1,"route":1},"id":3},{"from":{"id":4,"route":0},"to":{"id":1,"route":0},"id":5},{"from":{"id":4,"route":0},"to":{"id":2,"route":0},"id":6},{"from":{"id":1,"route":0},"to":{"id":13,"route":0},"id":16},{"from":{"id":10,"route":0},"to":{"id":11,"route":1},"id":12},{"from":{"id":13,"route":0},"to":{"id":11,"route":0},"id":14},{"from":{"id":11,"route":0},"to":{"id":13,"route":0},"id":15},{"from":{"id":13,"route":0},"to":{"id":17,"route":0},"id":18}],"groups":[{"id":0,"label":"root","children":[1,2,4,10,11,13,17],"position":{"x":0,"y":0}}],"sources":[],"links":[]}
@mikedewar

This comment has been minimized.

Copy link
Owner Author

mikedewar commented Nov 10, 2015

image

@mikedewar

This comment has been minimized.

Copy link
Owner Author

mikedewar commented Nov 10, 2015

this counts in increments of 1, starting from an initial condition. This example is a simple way of exploring the latch (top-middle) and the gate (bottom-right).

It works as follows:

  • the identity block on the left pushes the number 0 which is set as its in-route's value.
  • the first block, either when streamtools starts or on a graph reset, emits true when it receives the first 0 , and true thereafter
  • upon receipt of the first 0 and the first block's true message, the latch emits 0 on its true route.
  • the + block adds 1, emitting 1. This is seen in the log, and also sent to the gate block.
  • the delay block waits 1 second, which is set as its duration-route's value, then emits true which is set as its in-route's value.
  • once the gate receives both the 1 from the add block and the true from the delay block, it emits the 1 to the addition block.
  • upon receipt of the 1 message, the addition block adds 1, emitting 2 back to the gate, which then waits for the delay bock to emit true again, when it emits 2 on its out-route to the addition block
  • this loops continues!
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.