microevent 1.0.1 → 1.0.2

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: a1ba1e0f525074ba0b7132012ba2b76007969e4f
4
- data.tar.gz: 890926fd20a40e9d3e692d5e7a0c27fdc2d8333a
3
+ metadata.gz: fbf1f4dea535fbe569255678e4f67f0cd8e43020
4
+ data.tar.gz: 4884dcaf58058a989850f79a02c7d5a3b8382aac
5
5
  SHA512:
6
- metadata.gz: 47fa01a16da03ba26e5ed79ab9c976dcd38bf3195d622a76bcd25c0cbea59fe07a343f64fafa124d961e139cb77ae508e3de7e7d41c169f6c69d308f1b3bfe7d
7
- data.tar.gz: 74d59fa6e429feec70ac2ace9beb3fabce7cad5f604dc047e592a136ff3a0e5d5c1e80cb9ffdb43dacb87571e2f9df81a9fd105b64de281d4428259a5839192a
6
+ metadata.gz: 7f0cb47876884449a46f952adf7eb35f7b1f57110d64f518e98952dbc509f17f702bb62b830b737deeb0cadb0c436fc187e11d6ed9d97f00c44993e6c979dd2a
7
+ data.tar.gz: 2daea356bbbd803388a491855e39fa53f9e3f071d8379a5b01de9b6cc017cc8704113bea4977987caa30b6a599d910a08d594d9200e3301802fd58c6aaa0b485
@@ -1,3 +1,8 @@
1
+ ### 1.0.2
2
+
3
+ * Dupping event array before triggering for better thread safety
4
+
5
+
1
6
  ### 1.0.1
2
7
 
3
8
  * Fix wrong gem uploded to rubygems
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # MicroEvent.rb [![[travis]](https://travis-ci.org/janlelis/microevent.rb.png)](https://travis-ci.org/janlelis/microevent.rb)
1
+ # MicroEvent.rb [![[version]](https://badge.fury.io/rb/microevent.svg)](http://badge.fury.io/rb/microevent) [![[travis]](https://travis-ci.org/janlelis/microevent.rb.png)](https://travis-ci.org/janlelis/microevent.rb)
2
2
 
3
3
  MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by [MicroEvent.js](https://github.com/jeromeetienne/microevent.js), implemented in less than [20 lines of Ruby](https://github.com/janlelis/microevent.rb/blob/master/lib/microevent.rb).
4
4
 
@@ -46,7 +46,12 @@ end
46
46
  Klass.trigger :slot # => Go
47
47
  ```
48
48
 
49
- You will find more examples in the [tests](https://github.com/janlelis/microevent.rb/blob/master/spec/microevent_test.rb).
49
+ You will find more examples in the [tests](https://github.com/janlelis/microevent.rb/blob/master/spec/microevent_spec.rb).
50
+
51
+ ## Projects Using MicroEvent.rb
52
+
53
+ * [micrologger](https://github.com/janlelis/micrologger)
54
+
50
55
 
51
56
  ## MIT License
52
57
 
@@ -1,5 +1,5 @@
1
1
  module MicroEvent
2
- VERSION = "1.0.1".freeze
2
+ VERSION = "1.0.2".freeze
3
3
 
4
4
  def bind(event, &fn)
5
5
  @_ ||= Hash.new{ |h,k| h[k] = [] }
@@ -13,6 +13,6 @@ module MicroEvent
13
13
 
14
14
  def trigger(event, *args)
15
15
  @_ ||= Hash.new{ |h,k| h[k] = [] }
16
- !@_[event].each{ |fn| instance_exec(*args, &fn) }.empty?
16
+ !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty?
17
17
  end
18
18
  end
@@ -1,12 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
- require_relative 'lib/microevent'
3
+ require File.expand_path('../lib/microevent', __FILE__)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "microevent"
7
7
  gem.version = MicroEvent::VERSION
8
8
  gem.summary = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects.'
9
- gem.description = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by[MicroEvent.js and implemented in less than 20 lines of Ruby.'
9
+ gem.description = 'MicroEvent.rb is a event emitter library which provides the observer pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less than 20 lines of Ruby.'
10
10
  gem.license = "MIT"
11
11
  gem.authors = ["Jan Lelis"]
12
12
  gem.email = "mail@janlelis.de"
@@ -215,4 +215,27 @@ describe MicroEvent do
215
215
  assert_equal false, result
216
216
  end
217
217
  end
218
+
219
+ describe "thread safety" do
220
+ it "is thread safe when unbinding while triggering" do
221
+ mutex = Mutex.new
222
+ result = []
223
+
224
+ procs = (0...5000).map {
225
+ proc{ mutex.synchronize{ result << 42 } }
226
+ }
227
+ procs.each{ |proc|
228
+ object.bind :slot, &proc
229
+ }
230
+ thread = Thread.new do
231
+ procs.each{ |proc|
232
+ object.unbind :slot, &proc
233
+ }
234
+ end
235
+ object.trigger :slot
236
+ thread.join
237
+
238
+ assert_equal 5000, result.size
239
+ end
240
+ end
218
241
  end
metadata CHANGED
@@ -1,24 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: microevent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: MicroEvent.rb is a event emitter library which provides the observer
14
- pattern to Ruby objects. It is inspired by[MicroEvent.js and implemented in less
14
+ pattern to Ruby objects. It is inspired by MicroEvent.js and implemented in less
15
15
  than 20 lines of Ruby.
16
16
  email: mail@janlelis.de
17
17
  executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".README.md.swp"
22
21
  - ".gitignore"
23
22
  - ".travis.yml"
24
23
  - CHANGELOG.md
Binary file