File tree Expand file tree Collapse file tree 3 files changed +8
-3
lines changed Expand file tree Collapse file tree 3 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,10 @@ module Fiber::ExecutionContext
122
122
Thread .current.execution_context
123
123
end
124
124
125
+ def self.current ? : ExecutionContext ?
126
+ Thread .current.execution_context?
127
+ end
128
+
125
129
# :nodoc:
126
130
#
127
131
# Tells the current scheduler to suspend the current fiber and resume the
@@ -181,6 +185,7 @@ module Fiber::ExecutionContext
181
185
#
182
186
# Enqueues a fiber to be resumed inside the execution context.
183
187
#
184
- # May be called from any ExecutionContext (i.e. must be thread-safe).
188
+ # May be called from any ExecutionContext (i.e. must be thread-safe). May also
189
+ # be called from bare threads (outside of an ExecutionContext).
185
190
abstract def enqueue (fiber : Fiber ) : Nil
186
191
end
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ module Fiber::ExecutionContext
180
180
181
181
# :nodoc:
182
182
def enqueue (fiber : Fiber ) : Nil
183
- if ExecutionContext .current == self
183
+ if ExecutionContext .current? == self
184
184
# local enqueue: push to local queue of current scheduler
185
185
ExecutionContext ::Scheduler .current.enqueue(fiber)
186
186
else
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ module Fiber::ExecutionContext
102
102
103
103
# :nodoc:
104
104
def enqueue (fiber : Fiber ) : Nil
105
- if ExecutionContext .current == self
105
+ if ExecutionContext .current? == self
106
106
# local enqueue
107
107
Crystal .trace :sched , " enqueue" , fiber: fiber
108
108
@runnables .push(fiber)
You can’t perform that action at this time.
0 commit comments