Comments (15)
There was an unfortunate bug and this will be fixed in Ruby 3.1.1.
from async.
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.
Do you mean running IRB inside an Async block, and using Async IO objects as input/output to IRB?
from async.
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.
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.
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.
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.
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.
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.
The way I wanted to solve this was by having a separate process connect to the running process from a different terminal.
from async.
@aycabta wondering if you've had time to explore this?
from async.
This is now fixed in Async 2.0.
from async.
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.
Maybe this video helps answer that?
https://www.youtube.com/watch?v=9StgQAwR3kw
from async.
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)
- Unhandled Exception does not stop program running HOT 10
- [Enhanchment] Make alternate exception reporting (the colorful one) opt in. HOT 3
- [Question] How to stop a fiber? HOT 4
- Strange timeout bug. HOT 10
- Dynamic concurrency limiter / adaptive semaphore HOT 3
- Configure log level specificly for Async HOT 4
- Segmentation fault HOT 5
- ActiveRecord best practices support or documentation HOT 1
- [Question] What difference between `Async` and `Sync` HOT 1
- bundle error HOT 1
- Catch all Async errors and report to Sentry? (or other error reporting)
- How to wait for `.schedule`'d fibers to finish? HOT 7
- Properly managing interrupts (works for async v 1.31, "breaks" for async v 2.5.6) HOT 3
- Tasks signaling Conditions leave suspended Fibers behind HOT 8
- Error reporting difference between Sync{} and Async{}.wait HOT 2
- Understanding the difference of Sync usage within Falcon HOT 3
- macOS: `Errno::EINVAL: Invalid argument - IO_Event_Selector_KQueue_io_wait:IO_Event_Selector_KQueue_Waiting_register` HOT 18
- Stopping remaining tasks upon completion of one task HOT 2
- Blocking subprocess (popen3) HOT 10
- Sleep Hook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async.