GithubHelp home page GithubHelp logo

Comments (4)

milseman avatar milseman commented on May 31, 2024

I really like this idea, but I'm concerned that it just doesn't work out in practice. Writes can throw, a file descriptor might not be open for writing, and TextOutputStream is passed inout. Really, I think there needs to be a new/better pattern for streaming textual output than the one we have.

We could also consider throwing overloads of print and dump. Otherwise it might make sense to wait for a file stream concept.

from swift-system.

JetForMe avatar JetForMe commented on May 31, 2024

For stderr it seems we could just swallow the throw. What about a constrained version, like print(_:toStandard:[.out|.error]) that doesn't throw? Or I'd be okay with throwing ones, too, but I hate to deal with try?in front of all of those.

What wold a stream concept do?

from swift-system.

milseman avatar milseman commented on May 31, 2024

"Stream concept" would be a solution for System that provides the kind of functionality that FILE * does in C. You can write to it, it gets buffered locally, and it will flush on shutdown (or explicitly). The devil's in the details and how exactly we want to model it (e.g. unique ownership vs shared vs actor).

from swift-system.

GeorgeLyon avatar GeorgeLyon commented on May 31, 2024

In one of my project I faced a similar predicament where I wanted something to act as a TextOutputStream, but possibly throw (and be async). The solution I arrived at was to have a withTextOutputStream method like so:

public func withTextOutputStream(_ body: (inout TextOutputStream) -> Void) async throws {
  …
}

https://github.com/GeorgeLyon/Shwift/blob/f80750153de7ef28accca34d53d30bda95b8329b/Sources/Shell/Builtins.swift#L215-L220

It is a little verbose, but a similar solution might work well for FileDescriptor.

from swift-system.

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.