Comments (11)
I want to use this project from ruby script for weechat. How that works is that I can register hooks to get my callback called every X ms (in my case probably 10, to be determined), "do my work" (in this case I would check if any data arrived and process them) and return from the callback. At that point weechat takes back the control and I'm waiting for another callback call.
However once I leave the ruby code, the GVL is locked and any background processing is therefore not possible since no thread can acquire GVL... This could possibly be solved somehow by modifying the weechat's ruby plugin (I don't know), but still, I would like to keep this singlethreaded :)
from async.
Okay, there is an example how to do it with current interface.
from async.
I've implemented a similar design to this in the past.
We could certainly look at doing it. I think it's a reasonable approach.
Certain invariants are retained when using the current design, i.e. guarantees about task state.
from async.
If you want to try this another way, you could probably do the following (untested):
reactor = Async::Reactor.new
reactor.run do
# ...
reactor.stop
end
In the past, I've done something similar but there are sometimes useful variants like: run_once
, run_until(time)
, etc.
from async.
#run_once
would be great :) Thanks for the suggestion, this looks like I could avoid monkey-patching reactor all together, so will try it and see what it does. Thanks :)
from async.
The #stop
solution might be the simplest and easiest solution to use rather than #run_once
. Because it gives the flexibility to the user as to the stopping conditions (timeout, number of iterations). However, I'm not adverse to #run_once
as long as it doesn't make the code more fragile.
One thing I'd like to understand is what # Do some of my own work
is. In almost every case, you'd simply be better off scheduling a task or doing your own work on a separate thread. Is there some reason why this is useful/necessary?
from async.
Ah yep.
I think in the first case, can you try using #stop
. Can you report back whether that works or not? If not, let's see if we can find another solution (e.g. #run_once
).
from async.
How is this working out for you?
from async.
I'm sorry it took me so long to get back to this, I've picked example from async-io
and tried to do it (https://github.com/socketry/async-io/blob/master/spec/async/io/echo_spec.rb) , basically I've copied the code from the readme, however I cannot figure out where should I put the #stop
to in order for it to work :/
Could you please nudge me in the right direction? :)
from async.
That indeed seems to work! Thank you very much :)
from async.
You are most welcome, let me know how you get on. The only thing I can think of is it might still make sense to have a "Run one iteration" function rather than the timer... but for now this is the simplest thing I can think of without digging into the code.
from async.
Related Issues (20)
- Suggested API change HOT 26
- transient task hangs HOT 5
- Running shell command in an async task? HOT 1
- Links in Readme / Usage point to nonexistent pages HOT 1
- Errno::EAGAIN errors when stress testing async with regular IO objects HOT 8
- gets() hangs on Windows HOT 3
- with_timeout() cause gets() to raise Errno::ENOENT HOT 4
- cannot interrupt reactor if a queue is active HOT 3
- Task may have ended with unhandled exception when using Async combined with Sequel Fiber concurrency HOT 4
- 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)
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.