Method: Concurrently::Proc#call_nonblock
- Defined in:
- lib/all/concurrently/proc.rb
#call_nonblock(*args) ⇒ Object, Evaluation
Evaluates the concurrent proc in a non-blocking manner.
Evaluating the proc this way executes its block of code immediately until the result is available or the evaluation needs to wait.
Dealing with this method is similar to dealing with IO#*_nonblock.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/all/concurrently/proc.rb', line 219 def call_nonblock(*args) event_loop = EventLoop.current run_queue = event_loop.run_queue evaluation_bucket = [] result = begin fiber = event_loop.proc_fiber_pool.take_fiber # ProcFiberPool#take_fiber might have accessed the current evaluation # if it needs to wait for the next iteration to get a fiber. Reset the # current evaluation afterwards! previous_evaluation = run_queue.current_evaluation run_queue.current_evaluation = nil run_queue.evaluation_class = @evaluation_class fiber.resume [self, args, evaluation_bucket] ensure run_queue.current_evaluation = previous_evaluation run_queue.evaluation_class = nil end case result when Evaluation # The proc fiber if the proc cannot be evaluated without waiting. # Inject the evaluation into it so it can be concluded later. evaluation_bucket << result result when Exception raise result else result end end |