Skip to content

Async IO #1081

Closed
Closed

Description

@steveklabnik

Rust currently only includes synchronous IO in the standard library. Should we also have async IO as well, or leave that to an external crate? What would the design look like?

Moved from rust-lang/rust#6842

Related: #388

Activity

  1. Valloric commented on Apr 21, 2015

    @Valloric

    I don't see why this couldn't just remain in third-party external crates.

  2. steveklabnik commented on Apr 21, 2015

    @steveklabnik
    ContributorAuthor

    It can. Hence the 'community library' and 'libs' tags both.

  3. Anachron commented on Apr 22, 2015

    @Anachron

    Depends on who is actually maintaining the crate.

    In my opinion it should be at least some from the core members as once async and sync are not on the same page anymore, it can lead to confusion of even worse, broken projects.

    What I mean is this:
    Once the community wrote async versions of the std, the community will make decisions on itself, whether something should be one or another way.

    It will be hard to keep up-to-date and collaborateurs may not have digged into the core of Rust, though it will either go into a different direction or need someone to sync it with the syncronous version of the core.

  4. josephglanville commented on May 7, 2015

    @josephglanville

    The problem with "leaving it up to third party crates" is not having a blessed implementation that all libraries can interoperate with.

    This problem has already happened a few times now, namely Ruby and Python both have many competing and incompatible asynchronous IO libraries (gevent/twisted, celluloid/eventmachine).

    In and of itself that doesn't sound so bad until you realise the huge amount of stuff that gets built on top of said libraries. When you aren't then able to use powerful libraries with each other because they belong to different "async" camps then things get sad pretty quickly.

    Contrast this to C#, a language with built in async primitives, it also ships most of the higher level async integrated code (HTTP client etc). There is a single blessed solution and every library builds on top of it, they all interoperate and everyone is happy.

    I think it's super important to have async IO in core or blessed in some way to avoid fragmentation.

  5. m13253 commented on May 9, 2015

    @m13253

    I don't see why this couldn't just remain in third-party external crates.

    But I think there should be language-level support for some key features that are important to async programming. That includes:

    • Coroutines (we need compiler support to ensure thread-safe)
    • Python-styled yield statement (though it originally makes an iterator, in async programming it is used to save current execution point and get back later)
    • Or C#-styled async/await statement instead
    • Green threads (it is possible for 3rd-party libraries, but providing an "official" green threading library avoids different network libraries conflicting with each other because they used different green threading libraries)

    Yes we can already build a Node.JS-styled callback based async library -- that makes no sense. We need language-level support to build a modern one.

  6. flaub commented on May 14, 2015

    @flaub

    I think it's important to distinguish between traditional async I/O from use cases requiring the standard C select() API. I think that the existing synchronous I/O API is incomplete without the ability to cancel blocking calls. This doesn't seem to be robustly implementable without using select().

    I'd like to see the current synchronous I/O API extended to support cancellation without necessarily exposing the underlying select. The goal here is not to provide a highly scalable or particularly efficient way of scheduling I/O requests, but merely a way to cancel blocking calls.

  7. gotgenes commented on May 18, 2015

    @gotgenes
    • Python-styled yield statement (though it originally makes an iterator, in async programming it is used to save current execution point and get back later)
    • Or C#-styled async/await statement instead

    A minor correction to the "Python-styled" comment: it's technically yield from – syntax introduced in Python 3.3. (But yes, it is still based on generators).

    Regarding async/await, it's worth noting that this syntax was proposed for Python 3, and has been provisionally accepted for Python 3.5. PEP 492 lists a fair number of languages that have adopted or have proposed the async/await keywords. PEP 492 also does a fair job of describing the weaknesses of the yield from approach, as well as the advantages of async/await.

    Not that bandwagons are always the best reason to choose a direction, but async/await will become a very widespread idiom, and supporting it in Rust would provide great accessibility to those of us coming from other languages.

    Yes we can already build a Node.JS-styled callback based async library -- that makes no sense. We need language-level support to build a modern one.

    Hear, hear!

  8. ryanhiebert commented on May 18, 2015

    @ryanhiebert

    Being somebody familiar with Python and its async story, but not as familiar with compiled static languages, it would be helpful to me (and perhaps others) if somebody could comment on something that I'm familiar with from Python.

    In Python 3.5, async and await will be based on yield and yield from coroutines based on generators under the hood. This seems like a pretty elegant design to me, but I'd love to hear if there are any problems with that kind of approach.

  9. gotgenes commented on May 18, 2015

    @gotgenes

    In Python 3.5, async and await will be based on yield and yield from coroutines based on generators under the hood. This seems like a pretty elegant design to me, but I'd love to hear if there are any problems with that kind of approach.

    From @nathanaeljones's comment on rust-lang/rust#6842:

    One of the earliest comments asked about .NET's async system. It's a callback system, like most, but there is a lot of syntactic sugar, and the 3 different systems that are exposed have different levels of overhead.

    The most popular is C# async/await, which generates a closure and state machine to provide a continuation callback. Stack and thread context restoration is expensive, but you can opt out per-task.

    Now, what is "expensive"? I'm not sure. (I'm in the same boat as @ryanhiebert. I program mostly in Python. I was made aware of Rust by @mitsuhiko's blog posts.)

  10. lilith commented on May 18, 2015

    @lilith

    @gotgenes The expense depends on how much thread-local storage you're using. I know that it's low enough now that new APIs are async-only. This really depends on the language runtime (and the operating system); I don't think much can be learned about the performance implications by looking at other languages.

  11. phaux commented on Jun 30, 2015

    @phaux

    Would be cool to have something like GJ in the core.

  12. 160 remaining items

  13. chpio commented on Oct 8, 2017

    @chpio

    can https://tokio.rs/ be used together with the above async await?

    Yeap, Tokio is also just using futures. futures is the library at the heart of all async operations in rust.

    I'm not seeing an example

    https://github.com/alexcrichton/futures-await/blob/master/examples/echo.rs

  14. Ixrec commented on Oct 8, 2017

    @Ixrec
    Contributor

    @c0b https://internals.rust-lang.org/t/help-test-async-await-generators-coroutines/5835 might be the best place to start if you're trying to use the async/await experiment currently on nightly.

  15. leonerd commented on Jan 19, 2018

    @leonerd

    If it's of any interest, I've been busy implementing this idea in Perl, and observing that Python, C#, JavaScript and Dart all also do basically the same thing.

    Perl: https://metacpan.org/pod/Future::AsyncAwait
    Python: https://docs.python.org/3/library/asyncio-task.html
    C#: https://docs.microsoft.com/en-us/dotnet/csharp/async
    JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
    Dart: https://www.dartlang.org/articles/language/await-async

    If you have something of an "official language overview" page similar to those above, I'd like to add it to my collection.

  16. Centril commented on Feb 24, 2018

    @Centril
    Contributor

    Since discussion has moved on from here to tokio.rs, futures-rs, and other RFCs, I'll go ahead and close this issue.

  17. janhohenheim commented on Feb 26, 2018

    @janhohenheim

    @Centril I think it would be useful to link those issues for readers stumbling across this one. Do you happen to have them at hand?

  18. Centril commented on Feb 26, 2018

    @Centril
    Contributor

    Not so much about directly adding async IO directly to the standard library but rather enabling as crates:

  19. m13253 commented on Feb 26, 2018

    @m13253

    In reply to @Centril ,

    Since discussion has moved on from here to tokio.rs, futures-rs, and other RFCs

    This is what I (as well as some of us) are preventing from happening for years.
    Some of us are actually preventing this move to third-party crates.

    Lack of language-level async IO would cause incompatibility among third-party crates, as I have already stated before. Additionally, since Rust offers FFI, lack of language-level async IO would cause problems for C code to utilize concurrent programming.

    In fact, nearly all languages have async IO. But only those who provide language-level concurrency (e.g. Go, Python 3, C#, etc.) may have more or less chance to win the "language for the cloud" battle. We all agree that Rust is a powerful language far more than the need to build a browser engine. But we don't want to see Rust losing the cloud battlefield, do we?

    Really sorry if my language is offensive to you. But I disagree with your opinion that "we are relying on third-party crates". True concurrency requires implementations on compiler level that third-party crates cannot offer.


    Update: Thank you for your response below. ❤️

  20. Centril commented on Feb 26, 2018

    @Centril
    Contributor

    @m13253

    note: I'm only describing things as they are, not as they ought to be. =) Anyone is free to file full RFC proposals for libstd / language level async IO and we will judge those on their merits.

  21. Ixrec commented on Feb 26, 2018

    @Ixrec
    Contributor

    Note that "other RFCs" includes https://github.com/rust-lang/rfcs/blob/master/text/2033-experimental-coroutines.md, which basically is async/await syntax (albeit slightly less pretty since it's done with procedural macros for now). That seems like "language-level async IO" to me, even if it's not-so-secretly sugar over the futures library.

  22. leonerd commented on Feb 26, 2018

    @leonerd

    That seems like "language-level async IO" to me, even if it's not-so-secretly sugar over the futures library.

    That's OK. It's surface syntax sugar over futures in Perl as well. :) Probably true of many languages

  23. BatmanAoD commented on Apr 25, 2018

    @BatmanAoD
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-community-libraryArea: The RFC is related to a community library.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions