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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2505e85b820a9070243b7313c8a938c70719059b
4
- data.tar.gz: c017dfef00ccb8fc8a8173d8e301d5519f877865
3
+ metadata.gz: 5b44a65e6ca4c2d9302464aa583072c151d6716a
4
+ data.tar.gz: de61cb9e9cad50963591b46f003c1c63f3038633
5
5
  SHA512:
6
- metadata.gz: 9db0411ebec1d3625f3a918766a881ac7699b6a0b75334ce7c997c03c853bf6c03018af85ca1d6d3bfeb78ff72744a29015d7668ea80287f4b9ddb977677d979
7
- data.tar.gz: de31b57ec837be8fb312d76b41685fa2b78f606c3a8ad3df69704a212f297167d98dcd4d477fb66b0719f21876e78da11da653b22eebe77213947669ccfdf5cc
6
+ metadata.gz: 80ba93842ff6289f9830e9f14bfb690d9e502800991ca060c2d13d243ad871ee9dc56cfb39a5bd92870da20d48531c410fab900c4c0662e492ef5de3d926d222
7
+ data.tar.gz: 06c5a73f674c25962ab390fcc0509c0e4e88357bc74a732489ffee8e6294bdb67ec827ac8dff31e89d57f85d0c505fe159fcf7761f6d0c5c612e96b41b910458
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Metacosm
2
2
  # metacosm version
3
- VERSION = "0.1.8"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -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.apply(increment_counter_command)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metacosm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman