Advertisement
losinggeneration

Lua CSP

Jan 15th, 2013
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. function x(c)
  2.     for i=1, 10 do
  3.         c:IN(i)
  4.     end
  5. end
  6.  
  7. function y(c)
  8.     for i=1, 10 do
  9.         -- this blocks until something is received on the channel...
  10.         -- might instead need to be:
  11.         -- x=c:OUT()
  12.         -- print(x)
  13.         print(c:OUT())
  14.     end
  15. end
  16.  
  17. ch = Channel:new()
  18. swm = Swarm:new()
  19.  
  20. -- c is passed to each function in the swarm.
  21. -- An alternative would be something like:
  22. -- s = Swarm:new(c)
  23. -- To denote that each function in the swarm is going to be called with a parameter
  24. -- or it could be done like in the examples the channel is shared via closure
  25. swm:go(x, y, c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement