Comments (4)
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.
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.
"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.
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 {
…
}
It is a little verbose, but a similar solution might work well for FileDescriptor
.
from swift-system.
Related Issues (20)
- FilePath is Decodable, but not from a String
- Deprecated APIs are lacking availability information HOT 2
- Trunk compilation is broken with the Swift 5.7 compiler on linux HOT 1
- Release package version 1.4.0
- Assertion failure in FilePathParsing.swift HOT 3
- Build fails in release with: ld: Undefined symbols: static (extension in SystemPackage):SystemPackage._StrSlice.== infix(A, A) -> Swift.Bool HOT 1
- Update README for 1.4.0
- Release Testing for 1.4.0 HOT 2
- Does not compile for visionOS
- Fix `SystemString`'s `Collection` conformance
- Could you please remove the v-prefix from the version 0.0.2 tag? HOT 2
- Double-free with FilePath in Xcode 13 beta HOT 3
- Should `FileDescriptor.closeAfter` provide a `FileDescriptor` to the invoked closure?
- Add `FileDescriptor.openPipe`
- Add System.FilePath <-> SystemPackage.FilePath conversion?
- API Request: Splitting `POSIXPath` and `WindowsPath` out of `FilePath` HOT 2
- POSIX Spawn APIs HOT 1
- FileDescriptor.open(_:_:options:permissions:retryOnInterrupt:) should print an error message when trapping on unspecified permissions HOT 1
- Windows build is broken HOT 3
- Isolate Windows codebase from UN*X systems HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-system.