Giter Club home page Giter Club logo

Comments (4)

wusyong avatar wusyong commented on May 12, 2024

Looks like modules from piper are from async_std. You can just import them directly. Does something this work for you?

fn main() -> io::Result<()> {
    smol::run(async {
        let (s, r) = async_std::sync::channel(1);
        smol::Task::spawn( async move {s.send(2).await;} ).await;
        
        let x = r.recv().await;

        Ok(())
    })
}

from smol.

jjl avatar jjl commented on May 12, 2024

I'm trying to avoid having to spawn a new task.

I've started translating the current code into a Sending object. It's a bit horrific at the moment, but let's see how it goes.

from smol.

 avatar commented on May 12, 2024

I empathize with having to box futures to get a concrete type. This will get easier once the language supports impl Trait in more positions than it currently does.

Instead of using Task::spawn(), I suggest using .boxed() instead (exists in FutureExt) like so:

let (s, r) = piper::chan(1);
let fut: BoxFuture<'_, ()> = s.send("hello").boxed();
fut.await;

Looks like modules from piper are from async_std.

They're based on async-std's implementation of channels, but improved in many ways. For example, piper's channels can have capacity of zero. There's also try_recv(). They also have a successor of of WakerSet that is based on doubly-linked list and serves tasks in FIFO order, thus improving fairness.

from smol.

 avatar commented on May 12, 2024

This is something that will be solved by impl Trait in more places soon (hopefully!). Closing.

from smol.

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.