emittable 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/emittable.rb +2 -3
- data/spec/emittable_spec.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: becd44347409d49fe0f73a082a20c08ea032b3e253fca344eb614ca7a0206e52
|
4
|
+
data.tar.gz: 137a50fcb16470a87632aaf77fd10134d91bda5002bd5b1dc0b5ff3a05db3a6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb07ffc34c3e8f33627f87e5db21cc1fec5dcc445583fb63f343de1c5663fe05fa8886415b976560e17ad9509d7d0fe3d15335c28e2c18ced435b68651a9c7f6
|
7
|
+
data.tar.gz: 76303e7190a6211b173121e5d2ed3c8d96c8614e0494d511cf0667099de9556d22f095dc6947c405704e00a1a4e79c3dafddc14763c4c33af5a41a60b884f3a4
|
data/lib/emittable.rb
CHANGED
@@ -55,9 +55,8 @@ module Emittable
|
|
55
55
|
event_name = event_name.to_s
|
56
56
|
callbacks = nil
|
57
57
|
@emittable_mutex.synchronize do
|
58
|
-
callbacks = @emittable_events[event_name]
|
59
|
-
|
60
|
-
callbacks = callbacks.dup
|
58
|
+
callbacks = @emittable_events[event_name].to_a
|
59
|
+
callbacks = callbacks.dup # in case the array changes as we are iterating through the callbacks
|
61
60
|
end
|
62
61
|
# we are outside of the mutex so any callbacks are able to trigger an event from
|
63
62
|
# this class without deadlock
|
data/spec/emittable_spec.rb
CHANGED
@@ -61,12 +61,14 @@ RSpec.describe Emittable do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
context "after removing a callback" do
|
64
|
-
it "should sould
|
65
|
-
|
64
|
+
it "should sould not call it" do
|
65
|
+
$test = 0
|
66
|
+
callback = proc { $test += 1 }
|
66
67
|
@a.on(:event, &callback)
|
67
68
|
@a.trigger(:event)
|
68
69
|
@a.off(:event, callback)
|
69
|
-
|
70
|
+
@a.trigger(:event)
|
71
|
+
expect($test).to eql 1
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|