Class: Concurrently::Evaluation
- Inherits:
-
Object
- Object
- Concurrently::Evaluation
- Defined in:
- lib/all/concurrently/evaluation.rb,
lib/all/concurrently/evaluation/error.rb
Overview
Evaluations are not thread safe. They are operating on a fiber. Fibers cannot be resumed inside a thread they were not created in.
Concurrently::Evaluation
represents the evaluation of the main thread
outside of any concurrent evaluations.
An instance will be returned by Evaluation.current if called by the root evaluation.
Direct Known Subclasses
Defined Under Namespace
Classes: Error, TimeoutError
Instance Attribute Summary collapse
-
#waiting? ⇒ Boolean
readonly
Checks if the evaluation is waiting.
Class Method Summary collapse
-
.current ⇒ Evaluation
The evaluation that is currently running in the current thread.
Instance Method Summary collapse
-
#resume!(result = nil) ⇒ :resumed
Schedules the evaluation to be resumed.
Instance Attribute Details
#waiting? ⇒ Boolean (readonly)
Checks if the evaluation is waiting
45 46 47 |
# File 'lib/all/concurrently/evaluation.rb', line 45 def waiting? @waiting end |
Class Method Details
.current ⇒ Evaluation
The evaluation that is currently running in the current thread.
This method is thread safe. Each thread returns its own currently running evaluation.
26 27 28 |
# File 'lib/all/concurrently/evaluation.rb', line 26 def self.current EventLoop.current.run_queue.current_evaluation end |
Instance Method Details
#resume!(result = nil) ⇒ :resumed
The exclamation mark in its name stands for: Watch out! This method is potentially dangerous and can break stuff. It also needs to be complemented by an earlier call of Kernel#await_resume!.
Schedules the evaluation to be resumed
It needs to be complemented by an earlier call of Kernel#await_resume!.
This method is potentially dangerous. Kernel#wait, IO#await_readable, IO#await_writable and Proc::Evaluation#await_result are implemented with Kernel#await_resume!. Concurrent evaluations waiting because of them are resumed when calling #resume! although the event they are actually awaiting has not happened yet:
evaluation = concurrent_proc do
wait 1
await_resume!
end.call_nonblock
conproc.resume! # resumes the wait call prematurely
To use this method safely, make sure the evaluation to resume is waiting because of a manual call of Kernel#await_resume!.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/all/concurrently/evaluation.rb', line 92 def resume!(result = nil) run_queue = Concurrently::EventLoop.current.run_queue # Cancel running the fiber if it has already been scheduled to run; but # only if it was scheduled with a time offset. This is used to cancel the # timeout of a wait operation if the waiting fiber is resumed before the # timeout is triggered. run_queue.cancel(self, true) run_queue.schedule_immediately(self, result) :resumed end |