Git Product home page Git Product logo

Comments (15)

ioquatix avatar ioquatix commented on May 21, 2024 2

There was an unfortunate bug and this will be fixed in Ruby 3.1.1.

from async.

emiltin avatar emiltin commented on May 21, 2024 1

I guess I can start my Server (and the Async reactor) in a thread. But then I can't use things like waiting for states of the server, which internally use Async::Notification?

from async.

emiltin avatar emiltin commented on May 21, 2024 1

Do you mean running IRB inside an Async block, and using Async IO objects as input/output to IRB?

from async.

ioquatix avatar ioquatix commented on May 21, 2024

It should be possible to feed non-blocking IO into IRB, but I haven’t tried it.

@aycabta any thoughts? What interface is required to do it?

from async.

ioquatix avatar ioquatix commented on May 21, 2024

Yes it should be possible to do that. You can check if the IRB call is within an Async task and then use async io stdin/stdout.

from async.

emiltin avatar emiltin commented on May 21, 2024

Gave it a try, and it seems to work fairly well:
https://gist.github.com/emiltin/d382d1527d771afa8130b174e323539f

# counter.rb
require 'async'
class Counter
	attr_reader :count
	def initialize
		@count = 0
		Async do |task|
			loop do
				task.sleep 1
				@count = @count + 1
			end
		end
	end
end
Emils-MacBook-Air-2:async-irb emiltin$ ./irb
irb(main):001:0> require './counter'
=> true
irb(main):002:0> c=Counter.new
=> #<Counter:0x00007fcac906c750 @count=0>
irb(main):003:0> c.count
=> 2
irb(main):004:0> c.count     # let's wait a bit and look again
=> 17                        # yay, it's counting in the background!
irb(main):005:0> sleep 20    # will this work?
=> 20         
irb(main):006:0> c.count     # 20 seconds later
=> 24                        # not right, we need use async task.sleep

from async.

emiltin avatar emiltin commented on May 21, 2024

Looking at https://github.com/ruby/irb/blob/master/lib/irb/input-method.rb, encoding() and eof() probably also needs to be implemented.
Another thing that doesn't work is arrow-up to select previous lines, any idea why that is?

from async.

emiltin avatar emiltin commented on May 21, 2024

Sleeping can be done with Async::Task.current.sleep 10. Would it make sense to have a class method for putting the curent task to sleep, like Async.sleep?

from async.

emiltin avatar emiltin commented on May 21, 2024

When you have async tasks that output stuff in the background, it can be hard to see what you're typing. I was hoping irb sesions could be used to keep noisy tasks in the background, while you interact with them in a separate session.

But sessions are based on threads and background sessions seems to be put to sleep:

irb#1(main):009:0> jobs
=> #0->irb on main (#<Thread:0x00007fa697064088 sleep_forever>: stop)
#1->irb#1 on main (#<Thread:0x00007fa697888278@/Users/emiltin/.rbenv/versions/2.6.3/lib/ruby/2.6.0/irb/ext/multi-irb.rb:192 run>: running)

from async.

ioquatix avatar ioquatix commented on May 21, 2024

The way I wanted to solve this was by having a separate process connect to the running process from a different terminal.

from async.

ioquatix avatar ioquatix commented on May 21, 2024

@aycabta wondering if you've had time to explore this?

from async.

ioquatix avatar ioquatix commented on May 21, 2024

This is now fixed in Async 2.0.

from async.

emiltin avatar emiltin commented on May 21, 2024

Goods news!
How is it used? If I just use an Async block, it only returns once it's complete, as expected.

irb(main):008:0> t=Async {|task| task.sleep 2}      # blocks for 2 seconds
=> #<Async::Task:0x38720>
irb(main):009:0> t.status
=> :complete

How can I run async tasks, while interacting with irb at the same time?

from async.

bruno- avatar bruno- commented on May 21, 2024

Maybe this video helps answer that?

https://www.youtube.com/watch?v=9StgQAwR3kw

from async.

emiltin avatar emiltin commented on May 21, 2024

hi @bruno thank you, I just found it too! it basically show want i would like to do, but it seems to be a demo running a customized version of irb? at least i can't reproduce the behaviour with the standard irb in ruby 3.1.0. Async { binding.irb } blocks.

from async.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.