Skip to content

Commit

Permalink
Add Fiber#status (refs #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Jun 20, 2024
1 parent 4294393 commit 65c11a5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core_ext/fiber.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class Fiber
enum Status
Suspended
Running
Dead
end

def self.current : Fiber
Thread.current.current_fiber
end
Expand Down Expand Up @@ -71,6 +77,18 @@ class Fiber
# # @execution_context = ExecutionContext.current # <= infinite recursion
# end

def status : Status
if @alive
if @context.@resumable == 1
Status::Suspended
else
Status::Running
end
else
Status::Dead
end
end

def enqueue : Nil
execution_context.enqueue(self)
end
Expand Down

0 comments on commit 65c11a5

Please sign in to comment.