-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqueue.rb
More file actions
56 lines (46 loc) · 1.03 KB
/
queue.rb
File metadata and controls
56 lines (46 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Example of some basic features of queues. Uses strings as messages
# just to make the matching examples simple. See also queue2.rb.
require 'redshift'
include RedShift
class Receiver < Component
queue :q
transition do
wait :q => /time is now 2/
action do
msg = q.pop
puts "SPECIAL CASE! popped #{msg.inspect} at time #{world.clock}"
end
end
transition do
wait :q => [/time is/, /3/]
action do
msg = q.pop
puts "CONJUNCTION! popped #{msg.inspect} at time #{world.clock}"
end
end
transition do
wait :q => /time is/
action do
msg = q.pop
puts "popped #{msg.inspect} at time #{world.clock}"
end
end
end
class Sender < Component
link :receiver
flow {diff "t' = 1"}
transition do
guard "t>1"
reset :t => 0
action do
msg = "time is now #{world.clock}"
puts "pushed #{msg.inspect}"
receiver.q << msg
end
end
end
w = World.new
receiver = w.create Receiver
sender = w.create Sender
sender.receiver = receiver
w.evolve 5