Skip to content

Commit

Permalink
Unify EventLoop.create (#14661)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jun 10, 2024
1 parent 835b0c7 commit 897bd10
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
12 changes: 11 additions & 1 deletion src/crystal/system/event_loop.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
abstract class Crystal::EventLoop
# Creates an event loop instance
# def self.create : Crystal::EventLoop
def self.create : self
{% if flag?(:wasi) %}
Crystal::Wasi::EventLoop.new
{% elsif flag?(:unix) %}
Crystal::LibEvent::EventLoop.new
{% elsif flag?(:win32) %}
Crystal::IOCP::EventLoop.new
{% else %}
{% raise "Event loop not supported" %}
{% end %}
end

@[AlwaysInline]
def self.current : self
Expand Down
7 changes: 0 additions & 7 deletions src/crystal/system/unix/event_loop_libevent.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
require "./event_libevent"

# :nodoc:
abstract class Crystal::EventLoop
def self.create
Crystal::LibEvent::EventLoop.new
end
end

# :nodoc:
class Crystal::LibEvent::EventLoop < Crystal::EventLoop
private getter(event_base) { Crystal::LibEvent::Event::Base.new }
Expand Down
7 changes: 0 additions & 7 deletions src/crystal/system/wasi/event_loop.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# :nodoc:
abstract class Crystal::EventLoop
def self.create
Crystal::Wasi::EventLoop.new
end
end

# :nodoc:
class Crystal::Wasi::EventLoop < Crystal::EventLoop
# Runs the event loop.
Expand Down
7 changes: 0 additions & 7 deletions src/crystal/system/win32/event_loop_iocp.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
require "c/ioapiset"
require "crystal/system/print_error"

# :nodoc:
abstract class Crystal::EventLoop
def self.create
Crystal::IOCP::EventLoop.new
end
end

# :nodoc:
class Crystal::IOCP::EventLoop < Crystal::EventLoop
# This is a list of resume and timeout events managed outside of IOCP.
Expand Down

0 comments on commit 897bd10

Please sign in to comment.