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

Run tests on Windows. #184

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
- os: ubuntu
ruby: head
experimental: true
- os: windows
ruby: head
experimental: true

steps:
- uses: actions/checkout@v3
Expand Down
30 changes: 24 additions & 6 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def self.supported?
true
end

def self.windows?
::RUBY_PLATFORM =~ /mswin|mingw|cygwin/
end

def initialize(parent = nil, selector: nil)
super(parent)

Expand Down Expand Up @@ -167,12 +171,26 @@ def io_wait(io, events, timeout = nil)
end

if ::IO::Event::Support.buffer?
def io_read(io, buffer, length, offset = 0)
@selector.io_read(Fiber.current, io, buffer, length, offset)
end

def io_write(io, buffer, length, offset = 0)
@selector.io_write(Fiber.current, io, buffer, length, offset)
if Scheduler.windows?
def io_read(io, buffer, length, offset = 0)
Thread.new do
buffer.read(io, length, offset)
end.value
end

def io_write(io, buffer, length, offset = 0)
Thread.new do
buffer.write(io, length, offset)
end.value
end
else
def io_read(io, buffer, length, offset = 0)
@selector.io_read(Fiber.current, io, buffer, length, offset)
end

def io_write(io, buffer, length, offset = 0)
@selector.io_write(Fiber.current, io, buffer, length, offset)
end
end
end

Expand Down