Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 29, 2024. It is now read-only.
This repository was archived by the owner on Aug 29, 2024. It is now read-only.

async-io Async::IO::Endpoint#connect should work without Async reactor #56

Copy link
Copy link
@mrhardikjoshi

Description

@mrhardikjoshi
Issue body actions

Hello Everyone,

I am using echo/client.rb example without having Async wrapper call around it. I am aware some of this gem's feature like SharedEndpoint and Trap won't work without Async reactor, But I am focused on Endpoint connect/close, read/write and similar operations. As per my understanding those do not require to be run within Async reactor.

Following is how my changed example of echo/client.rb looks like:

require 'async'
require 'async/io/host_endpoint'
require 'async/io/stream'

endpoint = Async::IO::Endpoint.tcp('localhost', 4578)
# peer = endpoint.connect        # doesn't work
peer = Sync { endpoint.connect } # Works
stream = Async::IO::Stream.new(peer)

while true
  sleep 1
  stream.puts "Hello World!"
  puts stream.gets.inspect
end

This doesn't works when endpoint.connect is not wrapped in Async/Sync block. With following error

$ruby test.rb
.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.2.1/lib/async/task.rb:178:in `current': No async task available! (RuntimeError)
	from .rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-io-1.34.0/lib/async/io/host_endpoint.rb:55:in `connect'
	from test.rb:8:in `<main>'

Above exception is raised here while trying to get the current task task = Task.current. This current task is only used for annotation here and here. (I didn't use local address to bind so it won't need task to created another fiber => reference).

So my question: Is it correct to use Async::IO without Async reactor like above? and Should we change Async::IO::Endpoint#connect and Async::IO::Socket.connect methods to get the current task without raising exception and work outside of reactor too? If yes then I am happy to make a PR with these changes.

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.