Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: EventLoop::Polling::FiberEvent [fixup #14996] #15301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crystal/event_loop/polling.cr
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ abstract class Crystal::EventLoop::Polling < Crystal::EventLoop
# fiber interface, see Crystal::EventLoop

def create_resume_event(fiber : Fiber) : FiberEvent
FiberEvent.new(self, fiber, :sleep)
FiberEvent.new(:sleep, fiber)
end

def create_timeout_event(fiber : Fiber) : FiberEvent
FiberEvent.new(self, fiber, :select_timeout)
FiberEvent.new(:select_timeout, fiber)
end

# file descriptor interface, see Crystal::EventLoop::FileDescriptor
Expand Down
8 changes: 4 additions & 4 deletions src/crystal/event_loop/polling/fiber_event.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Crystal::EventLoop::Polling::FiberEvent
include Crystal::EventLoop::Event

def initialize(@event_loop : EventLoop, fiber : Fiber, type : Event::Type)
def initialize(type : Event::Type, fiber : Fiber)
@event = Event.new(type, fiber)
end

Expand All @@ -10,15 +10,15 @@ class Crystal::EventLoop::Polling::FiberEvent
seconds, nanoseconds = System::Time.monotonic
now = Time::Span.new(seconds: seconds, nanoseconds: nanoseconds)
@event.wake_at = now + timeout
@event_loop.add_timer(pointerof(@event))
EventLoop.current.add_timer(pointerof(@event))
end

# select timeout has been cancelled
def delete : Nil
return unless @event.wake_at?

@event.wake_at = nil
@event_loop.delete_timer(pointerof(@event))
EventLoop.current.delete_timer(pointerof(@event))
clear
end

# fiber died
Expand Down
Loading