metacosm 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/metacosm/simulation.rb +29 -0
- data/lib/metacosm/version.rb +1 -1
- data/spec/metacosm_spec.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b44a65e6ca4c2d9302464aa583072c151d6716a
|
4
|
+
data.tar.gz: de61cb9e9cad50963591b46f003c1c63f3038633
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80ba93842ff6289f9830e9f14bfb690d9e502800991ca060c2d13d243ad871ee9dc56cfb39a5bd92870da20d48531c410fab900c4c0662e492ef5de3d926d222
|
7
|
+
data.tar.gz: 06c5a73f674c25962ab390fcc0509c0e4e88357bc74a732489ffee8e6294bdb67ec827ac8dff31e89d57f85d0c505fe159fcf7761f6d0c5c612e96b41b910458
|
data/lib/metacosm/simulation.rb
CHANGED
@@ -1,9 +1,38 @@
|
|
1
1
|
module Metacosm
|
2
2
|
class Simulation
|
3
|
+
attr_accessor :running
|
3
4
|
def watch(model)
|
4
5
|
Frappuccino::Stream.new(model).on_value(&method(:receive))
|
5
6
|
end
|
6
7
|
|
8
|
+
def fire(command)
|
9
|
+
command_queue.push(command)
|
10
|
+
end
|
11
|
+
|
12
|
+
def command_queue
|
13
|
+
@command_queue ||= Queue.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def conduct!
|
17
|
+
@running = true
|
18
|
+
@conductor_thread = Thread.new { execute }
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
while @running
|
23
|
+
if (command=command_queue.pop)
|
24
|
+
# p [ :applying!, command: command ]
|
25
|
+
apply(command)
|
26
|
+
end
|
27
|
+
sleep 0.01
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def halt!
|
32
|
+
@running = false
|
33
|
+
@conductor_thread.terminate
|
34
|
+
end
|
35
|
+
|
7
36
|
def apply(command)
|
8
37
|
handler_for(command).handle(command.attrs)
|
9
38
|
end
|
data/lib/metacosm/version.rb
CHANGED
data/spec/metacosm_spec.rb
CHANGED
@@ -28,8 +28,11 @@ describe "a simple simulation (fizzbuzz)" do
|
|
28
28
|
increment: 1, counter_id: counter_model.id
|
29
29
|
)
|
30
30
|
|
31
|
-
sim.
|
31
|
+
sim.fire(increment_counter_command)
|
32
32
|
|
33
|
+
expect(counter_view.value).to eq(0) # => 0
|
34
|
+
sim.conduct!
|
35
|
+
sleep 0.2
|
33
36
|
# model is updated which triggers view changes
|
34
37
|
expect(counter_view.value).to eq(1) # => 1
|
35
38
|
|
@@ -46,6 +49,8 @@ describe "a simple simulation (fizzbuzz)" do
|
|
46
49
|
CounterIncrementedEvent,
|
47
50
|
BuzzEvent,
|
48
51
|
CounterIncrementedEvent])
|
52
|
+
|
53
|
+
sim.halt!
|
49
54
|
end
|
50
55
|
|
51
56
|
context "one command once" do
|