Git Product home page Git Product logo

Comments (11)

graywolf-at-work avatar graywolf-at-work commented on May 21, 2024 1

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.

ioquatix avatar ioquatix commented on May 21, 2024 1

Okay, there is an example how to do it with current interface.

from async.

ioquatix avatar ioquatix commented on May 21, 2024

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.

ioquatix avatar ioquatix commented on May 21, 2024

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.

graywolf avatar graywolf commented on May 21, 2024

#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.

ioquatix avatar ioquatix commented on May 21, 2024

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.

ioquatix avatar ioquatix commented on May 21, 2024

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.

ioquatix avatar ioquatix commented on May 21, 2024

How is this working out for you?

from async.

graywolf-at-work avatar graywolf-at-work commented on May 21, 2024

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.

graywolf-at-work avatar graywolf-at-work commented on May 21, 2024

That indeed seems to work! Thank you very much :)

from async.

ioquatix avatar ioquatix commented on May 21, 2024

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)

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.