Comment by rowanG077

Comment by rowanG077 20 hours ago

7 replies

Where do you think the Io parameter comes from? If you change some function to do something async and now suddenly you require an Io instance. I don't see the difference between having to modify the call tree to be async vs modifying the call tree to pass in an Io token.

messe 19 hours ago

Synchronous Io also uses the Io instance now. The coloring is no longer "is it async?" it's "does it perform Io"?

This allows library authors to write their code in a manner that's agnostic to the Io runtime the user chooses, synchronous, threaded, evented with stackful coroutines, evented with stackless coroutines.

  • simonask 12 hours ago

    The interesting question was always “does it perform IO”.

  • metaltyphoon 13 hours ago

    Except that now your library code lost context on how it runs. If you meant it to be sync and the caller gives you an multi threaded IO your code can fail in unexpected ways.

    • messe 10 hours ago

      How so? Aside from regular old thread safety issues that is.

      • metaltyphoon 10 hours ago

        This is exactly the problem, thread safety. The function being supplied with std.Io needs to understand what implementation is being used to take precautions with thread safety, in case a std.Io.Threaded is used. What if this function was designed with synchrony in mind, how do you prevent it taking a penalty guarding against a threaded version of IO?

        • messe 3 hours ago

          The function being called has to take into account thread safety anyway even if it doesn't do IO. This is an entirely orthogonal problem, so I can't really take it seriously as a criticism of Zig's approach. Libraries in general need to be designed to be thread-safe or document otherwise regardless of if the do IO, because a calling program could easily spin up a few threads and call it multiple times.

          > What if this function was designed with synchrony in mind, how do you prevent it taking a penalty guarding against a threaded version of IO?

          You document it and state that it will take a performance penalty in multithreaded mode? The same as any other library written before this point.

  • rowanG077 19 hours ago

    Rust also allows writing async code that is agnostic to the async runtime used. Subsuming async under Io doesn't change much imo.