wires 0.5.7 → 0.5.8
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/wires/base/channel.rb +25 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b26a6c6020e7909d89cd9a3f87da0e721ffe9ea
|
4
|
+
data.tar.gz: 021904136183e2874fb7cc9e054642cf1a8dd04b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46a6c48fe72d56da690f27811eac4087560c1b7eb24e53c1e066543eb3036add3965706092a19ba6dfd6a7275f7a6a7a74c8cda5318426b3fff3b747ac00f081
|
7
|
+
data.tar.gz: f2d03f3ff04f99d04158b6170f02b44f661b1bc171c1f275a0898e95bbeda923a5f080a011ee6b1b87545b03321f2d81fd2e298b9d7d20a96731f0ce202e7b12
|
data/lib/wires/base/channel.rb
CHANGED
@@ -101,7 +101,7 @@ module Wires.current_network::Namespace
|
|
101
101
|
# then the handler is executed, and yielded the event object and the {#name}
|
102
102
|
# of the channel upon which {#fire} was called as arguments.
|
103
103
|
#
|
104
|
-
# @param
|
104
|
+
# @param events [<Symbol, Event>] the event pattern(s)
|
105
105
|
# to listen for. If the pattern is a symbol or event with a type and no
|
106
106
|
# other arguments, any event with that type will be heard. If the
|
107
107
|
# pattern is an event that has other arguments, each of the arguments
|
@@ -109,7 +109,7 @@ module Wires.current_network::Namespace
|
|
109
109
|
# fired event for it to be heard by the handler, but the fired event may
|
110
110
|
# also include other arguments that were not declared in the pattern
|
111
111
|
# and still be heard by the handler (see {Event#=~}).
|
112
|
-
# @param
|
112
|
+
# @param callable [Proc] the executable code to register as a handler
|
113
113
|
# on this channel for the given pattern.
|
114
114
|
#
|
115
115
|
# @return [Proc] the +&callable+ given, which has been extended with an
|
@@ -167,7 +167,7 @@ module Wires.current_network::Namespace
|
|
167
167
|
# the +#unregister+ method that was injected into the +&callable+
|
168
168
|
# (refer to the return value of {#register})
|
169
169
|
#
|
170
|
-
# @param
|
170
|
+
# @param callable [Proc] the same callable object that was given to
|
171
171
|
# (and returned by) {#register}.
|
172
172
|
#
|
173
173
|
# @return [Boolean] +true+ if the callable was previously {#register}ed
|
@@ -208,9 +208,9 @@ module Wires.current_network::Namespace
|
|
208
208
|
# @param [Event, Symbol] event the event to be fired, as an Event or Symbol.
|
209
209
|
# In this context, a Symbol is treated as an 'empty' Event of that type
|
210
210
|
# (see to {Symbol#[]}).
|
211
|
-
# @param [Boolean]
|
211
|
+
# @param [Boolean] blocking when true, the method will wait to return
|
212
212
|
# until all handlers have finished their execution.
|
213
|
-
# @param [Boolean]
|
213
|
+
# @param [Boolean] parallel when true, the handlers will be executed in
|
214
214
|
# parallel, if there are more than one; otherwise, they will be executed
|
215
215
|
# serially (in an undefined order). Unless otherwise specified, this
|
216
216
|
# parameter will be set to the opposite of the value of the +:blocking+
|
@@ -292,9 +292,9 @@ module Wires.current_network::Namespace
|
|
292
292
|
end
|
293
293
|
|
294
294
|
# Synchronize execution of this thread to an incoming event.
|
295
|
-
#
|
296
|
-
#
|
297
|
-
#
|
295
|
+
# The user block will be executed, and will not return until a matching
|
296
|
+
# incoming event has been fired
|
297
|
+
# (see the {SyncHelper})
|
298
298
|
#
|
299
299
|
# @note In order to use this method correctly, the "action" that causes the
|
300
300
|
# incoming event to be fired should happen within the user block. If
|
@@ -303,26 +303,27 @@ module Wires.current_network::Namespace
|
|
303
303
|
# As long as the feedback event happens after execution of the user block
|
304
304
|
# has begun, the event is guaranteed to be caught and processed.
|
305
305
|
#
|
306
|
-
# @param
|
306
|
+
# @param events [<Symbol, Event>] the event pattern(s) filter
|
307
307
|
# to listen with. (see {#register}).
|
308
308
|
# @param timeout [Fixnum] the timeout, in seconds.
|
309
309
|
# (see {SyncHelper#wait}).
|
310
|
-
# @param
|
310
|
+
# @param block [Proc] the user block. This block will be executed inline
|
311
311
|
# and passed an instance of {SyncHelper}. Within this block, the helper
|
312
312
|
# should be configured using its methods. Optionally, {SyncHelper#wait}
|
313
313
|
# can be called to wait in a specific location in the block. Otherwise,
|
314
314
|
# it will be called implicitly at the end of the block.
|
315
315
|
#
|
316
|
+
# @!method sync_on(*events, timeout:nil, &block)
|
316
317
|
def sync_on(*events, timeout:nil, &block)
|
317
318
|
SyncHelper.new(events, self, timeout:timeout, &block)
|
318
319
|
nil
|
319
320
|
end
|
320
321
|
|
321
|
-
# Helper class passed to user block in {Channel#
|
322
|
+
# Helper class passed to user block in {Channel#sync_on} method.
|
322
323
|
# Read here for how to use the helper, but never instantiate it yourself.
|
323
324
|
class SyncHelper
|
324
325
|
|
325
|
-
# Don't instantiate this class directly, use {Channel#
|
326
|
+
# Don't instantiate this class directly, use {Channel#sync_on}
|
326
327
|
# @api private
|
327
328
|
def initialize(events, channel, timeout:nil)
|
328
329
|
@timeout = timeout
|
@@ -330,9 +331,16 @@ module Wires.current_network::Namespace
|
|
330
331
|
@conditions = []
|
331
332
|
@executions = []
|
332
333
|
@received = []
|
334
|
+
@thread = Thread.current
|
333
335
|
|
334
336
|
# Create the temporary event handler to capture incoming matches
|
335
|
-
proc = Proc.new
|
337
|
+
proc = Proc.new do |e,c|
|
338
|
+
if Thread.current==@thread
|
339
|
+
snag e,c
|
340
|
+
else
|
341
|
+
@lock.synchronize { snag e,c }
|
342
|
+
end
|
343
|
+
end
|
336
344
|
|
337
345
|
# Run the user block within the lock and wait afterward if they didn't
|
338
346
|
@lock.synchronize {
|
@@ -345,7 +353,7 @@ module Wires.current_network::Namespace
|
|
345
353
|
|
346
354
|
# Add a condition which must be fulfilled for {#wait} to find a match.
|
347
355
|
#
|
348
|
-
# @param
|
356
|
+
# @param block [Proc] the block specifiying the condition to be met.
|
349
357
|
# It will be passed the event and channel, and the truthiness of its
|
350
358
|
# return value will be evaluated to determine if the condition is met.
|
351
359
|
# It will only be executed if the +[event,channel]+ pair fits the
|
@@ -358,7 +366,7 @@ module Wires.current_network::Namespace
|
|
358
366
|
|
359
367
|
# Add a execution to run on the matching event for each {#wait}.
|
360
368
|
#
|
361
|
-
# @param
|
369
|
+
# @param block [Proc] the block to be executed.
|
362
370
|
# It will only be executed if the +[event,channel]+ pair fits the
|
363
371
|
# filter and met all of the conditions to fulfill the {#wait}.
|
364
372
|
# The block will not be run if the {#wait} times out.
|
@@ -368,7 +376,7 @@ module Wires.current_network::Namespace
|
|
368
376
|
nil
|
369
377
|
end
|
370
378
|
|
371
|
-
# Wait for exactly one matching event meeting all {#
|
379
|
+
# Wait for exactly one matching event meeting all {#condition}s to come.
|
372
380
|
#
|
373
381
|
# @note This will be called once implicitly at the end of the user block
|
374
382
|
# unless it gets called explicitly somewhere within the user block.
|
@@ -388,7 +396,7 @@ module Wires.current_network::Namespace
|
|
388
396
|
# Loop through each result, making sure it matches the conditions,
|
389
397
|
# returning nil if the wait timed out and didn't push into @received
|
390
398
|
loop do
|
391
|
-
@cond.wait @lock, timeout
|
399
|
+
@cond.wait @lock, timeout if @received.empty?
|
392
400
|
result = @received.pop
|
393
401
|
return nil unless result
|
394
402
|
break if !@conditions.detect { |blk| !blk.call *result }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wires
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: threadlock
|