socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.14k stars 88 forks source link

examples/callback/loop.rb is broken #118

Closed troex closed 2 years ago

troex commented 3 years ago
$ bundle exec ruby loop.rb
  0.0s    error: Async::Task [oid=0x3fead410a370] [ec=0x3fead410a2f8] [pid=2434] [2021-06-19 03:49:14 +0300]
               |   NoMethodError: undefined method `after' for #<Async::Task:0x00007fd5a82146e0>
               |   → loop.rb:17 in `block in run'
               |     ~/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/async-1.29.0/lib/async/task.rb:263 in `block in make_fiber'

I guess it's after d6d80a3d613b359d5fe9c90be63fe64bdb26ba27 commit, I'm trying to get how all your async stuff works together - examples and code are the only way to get it all

jedschneider commented 2 years ago

changing the method call to @reactor.sleep avoids the error, but the second task:

  while true
    callback.run(0)
    puts 'Sleeping for 1 second'
    sleep(1)
  end

never seems to get executed. I agree, this is edge enough that more complete examples are really needed. Thanks for all the hard work pushing Ruby ahead in this space!

ioquatix commented 2 years ago

I've updated the example, it should work correctly now. Feel free to ask more questions or suggest improvements.