Class: Smith::Workflow::PreparedStepExecutionScope
- Inherits:
-
Object
- Object
- Smith::Workflow::PreparedStepExecutionScope
- Defined in:
- lib/smith/workflow/prepared_step_execution_scope.rb
Instance Method Summary collapse
- #activate!(thread, fiber = Fiber.current) ⇒ Object
- #active_for?(thread, fiber = Fiber.current) ⇒ Boolean
- #binding_accessible_for?(thread, fiber = Fiber.current) ⇒ Boolean
- #close!(thread = nil, fiber = Fiber.current) ⇒ Object
-
#initialize ⇒ PreparedStepExecutionScope
constructor
A new instance of PreparedStepExecutionScope.
- #within_branch(&block) ⇒ Object
Constructor Details
#initialize ⇒ PreparedStepExecutionScope
Returns a new instance of PreparedStepExecutionScope.
11 12 13 14 15 16 17 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 11 def initialize @mutex = Mutex.new @phase = :issued @thread = nil @fiber = nil @branch_fibers = {}.compare_by_identity end |
Instance Method Details
#activate!(thread, fiber = Fiber.current) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 19 def activate!(thread, fiber = Fiber.current) Thread.handle_interrupt(Object => :never) do @mutex.synchronize do raise WorkflowError, "prepared-step execution scope is no longer available" unless @phase == :issued @phase = :active @thread = thread @fiber = fiber end end end |
#active_for?(thread, fiber = Fiber.current) ⇒ Boolean
59 60 61 62 63 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 59 def active_for?(thread, fiber = Fiber.current) @mutex.synchronize do @phase == :active && (owner?(@thread, @fiber, thread, fiber) || branch_owner?(thread, fiber)) end end |
#binding_accessible_for?(thread, fiber = Fiber.current) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 65 def binding_accessible_for?(thread, fiber = Fiber.current) @mutex.synchronize do @phase == :issued || (@phase == :active && (owner?(@thread, @fiber, thread, fiber) || branch_owner?(thread, fiber))) end end |
#close!(thread = nil, fiber = Fiber.current) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 31 def close!(thread = nil, fiber = Fiber.current) Thread.handle_interrupt(Object => :never) do @mutex.synchronize do if @phase == :active && thread && !owner?(@thread, @fiber, thread, fiber) raise WorkflowError, "prepared-step execution scope belongs to another thread or fiber" end raise WorkflowError, "prepared-step execution still has active branch fibers" unless @branch_fibers.empty? @phase = :closed @thread = nil @fiber = nil end end end |
#within_branch(&block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/smith/workflow/prepared_step_execution_scope.rb', line 46 def within_branch(&block) thread = Thread.current fiber = Fiber.current Thread.handle_interrupt(Object => :never) do enter_branch!(thread, fiber) begin Thread.handle_interrupt(Object => :immediate, &block) ensure leave_branch!(thread, fiber) end end end |