concurrently 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2433cf85e8e22dae4f8753c3f0bf8da68d0a307
4
- data.tar.gz: 5fc75f82d8f23b989b9f73171cb11aa8dd7dc6e7
3
+ metadata.gz: e10c69de9f9db4d13d7411544b336709be235688
4
+ data.tar.gz: a519b852d6ac6d07689daf39bd893fe1594c76eb
5
5
  SHA512:
6
- metadata.gz: 6a69bfe30abb26229e12195fc514c1a2766c0cf1531a5c72a4bf872ef358deaa5e28eae06eae537786f82a159a0071695913b93cc367989d30b90cc489b18879
7
- data.tar.gz: 28990344bb12e54ca9318f7396753e2a929cdbf80a8942ce2c00a2742b4e82a003c4e7c3db5e1f0001658bcbb815fd821cd3b1fc0bdbd8b1df0fddd2c30155cc
6
+ metadata.gz: e81443aec073e777bb7bdb18a293383716d66028a884d773208205aae52a15f2af993ed8f427f78e4515d83b379b07ee287c3d5f1ac2f10c478267258aff2872
7
+ data.tar.gz: 87102e7ee79831c03975175f52527b78da04100d6ddaaca56e479b208f59d03a362ea5ddbf3df16f08d37bf41d5157978c222f1b3c1afbb3e920f3e3b6d7b3e2
@@ -178,8 +178,8 @@ managing IOs (e.g. closing them).
178
178
  Every evaluation rescues the following errors: `NoMemoryError`, `ScriptError`,
179
179
  `SecurityError`, `StandardError` and `SystemStackError`. These are all errors
180
180
  that should not have an immediate influence on other evaluations or the
181
- application as a whole. They will not leak to the event loop and will not tear
182
- it down.
181
+ application as a whole. They will be rescued and do not leak to the event loop
182
+ and thus will not tear it down.
183
183
 
184
184
  All other errors happening during an evaluation *will* tear down the event
185
185
  loop. These error types are: `SignalException`, `SystemExit` and the general
@@ -35,7 +35,10 @@ module Concurrently
35
35
  # @private
36
36
  #
37
37
  # The fiber the evaluation runs inside.
38
- attr_reader :fiber
38
+ def __resume__(result)
39
+ @scheduled = false
40
+ @fiber.resume result
41
+ end
39
42
 
40
43
  # @!attribute [r] waiting?
41
44
  #
@@ -73,7 +76,7 @@ module Concurrently
73
76
  # because of a manual call of {Kernel#await_resume!}.
74
77
  #
75
78
  # @return [:resumed]
76
- # @raise [Error] if the evaluation is not waiting
79
+ # @raise [Error] if the evaluation is already scheduled to resume
77
80
  #
78
81
  # @example
79
82
  # # Control flow is indicated by (N)
@@ -90,6 +93,9 @@ module Concurrently
90
93
  # # (5)
91
94
  # evaluation.await_result # => :result
92
95
  def resume!(result = nil)
96
+ raise Error, "already scheduled to resume" if @scheduled
97
+ @scheduled = true
98
+
93
99
  run_queue = Concurrently::EventLoop.current.run_queue
94
100
 
95
101
  # Cancel running the fiber if it has already been scheduled to run; but
@@ -96,7 +96,7 @@ module Concurrently
96
96
  evaluation.resume result
97
97
  when Proc::Evaluation
98
98
  @current_evaluation = evaluation
99
- evaluation.fiber.resume result
99
+ evaluation.__resume__ result
100
100
  when Evaluation
101
101
  @current_evaluation = nil
102
102
  Fiber.yield result
@@ -235,12 +235,22 @@ module Concurrently
235
235
  @concluded = true
236
236
 
237
237
  if Fiber.current != @fiber
238
- # Cancel fiber by resuming it with itself as argument
239
- @fiber.resume @fiber
238
+ # Cancel its fiber by resuming it with itself as argument
239
+ @fiber.resume Cancelled
240
240
  end
241
241
 
242
242
  @awaiting_result.each{ |evaluation, override| evaluation.resume! (override or result) }
243
243
  :concluded
244
244
  end
245
+
246
+ # Schedules the evaluation to be resumed
247
+ #
248
+ # For details see: {Concurrently::Evaluation#resume!}
249
+ #
250
+ # @raise [Evaluation::Error] if the evaluation is already concluded
251
+ def resume!(*)
252
+ raise Evaluation::Error, "already concluded to #{@result.inspect}" if @concluded
253
+ super
254
+ end
245
255
  end
246
256
  end
@@ -20,7 +20,7 @@ module Concurrently
20
20
  while true
21
21
  evaluation_bucket ||= EMPTY_EVALUATION_BUCKET
22
22
 
23
- result = if proc == self
23
+ result = if proc.equal? Proc::Evaluation::Cancelled
24
24
  # If we are given this very fiber when starting itself it means it
25
25
  # has been evaluated right before its start. In this case just
26
26
  # yield back to the evaluating fiber.
@@ -31,9 +31,9 @@ module Concurrently
31
31
 
32
32
  :cancelled
33
33
  elsif not Proc === proc
34
- # This should never happen. If it does it means something with code
35
- # of this library is not right.
36
- raise Concurrently::Error, "concurrent proc not started properly."
34
+ raise Concurrently::Error, "Concurrent evaluation not started " <<
35
+ "properly. This should never happen and if it does it means " <<
36
+ "there is a bug in Concurrently."
37
37
  else
38
38
  begin
39
39
  result = proc.__proc_call__ *args
@@ -4,5 +4,5 @@
4
4
  # The namespace this library lives in
5
5
  module Concurrently
6
6
  # The version
7
- VERSION = "1.1.0"
7
+ VERSION = "1.1.1"
8
8
  end
@@ -131,13 +131,11 @@ module Kernel
131
131
  end
132
132
  evaluation.instance_variable_set :@waiting, false
133
133
 
134
- # If result is this very evaluation it means this evaluation has been evaluated
135
- # prematurely.
136
- if evaluation.fiber == result
134
+ if Concurrently::Proc::Evaluation::Cancelled.equal? result
137
135
  run_queue.cancel evaluation # in case the evaluation has already been scheduled to resume
138
136
  raise Concurrently::Proc::Evaluation::Cancelled, ''
139
- elsif Concurrently::Evaluation::TimeoutError == result
140
- raise result, "evaluation timed out after #{seconds} second(s)"
137
+ elsif Concurrently::Evaluation::TimeoutError.equal? result
138
+ raise Concurrently::Evaluation::TimeoutError, "evaluation timed out after #{seconds} second(s)"
141
139
  else
142
140
  result
143
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrently
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Aue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-10 00:00:00.000000000 Z
11
+ date: 2017-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r