Code Monkey home page Code Monkey logo

Comments (4)

vlovich avatar vlovich commented on August 24, 2024

UPDATE: Never mind. The reason I was seeing blocking is because I had a background task spinning on a future that always returned an error so it never yielded. So not relevant to the above & still confused by the note.

Ok, I am seeing scenarios where the Timer never returns if I await a tokio oneshot receiver and attach an .or with a timer to that future:

   let (_tx, rx) = tokio::oneshot::channel();
   rx.or(async move {
      glommio::sleep(Duration::from_millis(30));
   }).await // Deadlock!!!

The timeout code does work if I use glommio::timeout so I suspect this deadlock is what the Timer docs refer to. What's confusing is that on the front page of the docs the example has:

    let timeout = async {
        Timer::new(Duration::from_secs(10)).await;
        Err(io::Error::new(io::ErrorKind::TimedOut, "").into())
    };
    let stream = TcpStream::connect("::80").or(timeout).await?;

which would then seem like an erroneous example to have without the warning / an explanation of why this example might work but others following the same pattern won't in other cases (or maybe the example itself doesn't work which would be even worse).

from glommio.

vlovich avatar vlovich commented on August 24, 2024

@glommer if you get a chance I'd love to understand what the warning means if you remember.

from glommio.

glommer avatar glommer commented on August 24, 2024

The wording there is not the best, since it doesn't really block it.
What it means is that given Rust's concurrency model, calling .await will - as you put it - delay the current task.

I think I still had the seastar model in my mind when I wrote that code, in which a future starts executing immediately when you call it, and in my mind this behavior was "blocking"-like (but hey, it's been a while)

from glommio.

vlovich avatar vlovich commented on August 24, 2024

Ok. I'll put up a PR to clear up the wording.

from glommio.

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.