-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deferreds, file read, and filesystem API #48
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
squaremo
force-pushed
the
io
branch
2 times, most recently
from
November 29, 2018 12:07
6302963
to
995c8f1
Compare
On two layers: - a flatbuffer table def for invoking the (hypothetical) Read procedure - and lower level, defs for the protocol dealing with deferred values
To have functions in JavaScript that will call into Go code to do I/O, we need a bit of bookkeeping and a bit of protocol. This commit adds some of the required machinery, in the package `deferred`. This is wired into the runtime, and used in the implementation of a `read` built-in. Lacking: - the JavaScript side of the machinery - ability to cancel an outstanding request - a non-silly implementation of read - non-silly scheduling of requests
This implements the JavaScript side of deferreds; mainly, - decoding results from requests and turning them into promises - installing a handler for async messages coming from the runtime (Go code), decodes them, and resolves the deferreds
In particular: - `Response` is too generic, use `DeferredResponse` (and other similar renames) - Factor out `Error` since it will surely be useful elsewhere - Resolution -> Fulfilmenet because it seems to fit common usage better
This commit implements read, and ensures the test for it passes. So that I can (conveniently) check that reading a file gets the contents of the file, I've added a `Raw` format, which prints the _stringified_ value. I expect `Raw` to be useful for things other than the single test, of course :-)
Closed
This adds Go and JS code (and flatbuffers schema) for - info(path), to get file info (whether or not it's a directory, basically) - dir(path) to get a directory listing (of file infos) The design is not settled; in particular, - info() reports a path, while dir() reports basenames - there are extra fields I guessed at in the schema that I've not included in the Go or JS
In flatbuffers, `string` means a UTF8 string, which is not interchangeable with an array of bytes. For file contents, it's more appropriate, and will save heartache when dealing with checksums, etc., to send bytes as bytes. In flatbuffers that's a `[ubyte]` (vector of unsigned bytes), and happily it does generate some convenience methods for setting and getting useful values in both Go and JavaScript. This means we have to do a tiny amount more work if we want to write a string back out. `write` ought to accept a byte array; but for now, it expects a string, and it's trickier to account for JSON-encoded things if we have to send them as bytes. Though not impossible.
It's convenient to have the path to a file or directory given to you rather than having to construct it, since the filesystem library functions _accept_ paths. But occasionally (e.g., for constructing ConfigMaps, where the keys are the filenames) it's handy to have the name right there too. So, return both.
Same as for info() -- drop a file if it has mode bits other than being a directory.
This avoids the non-determinism inherent in listing a directory (especially one that might have been git cloned, or untarred, since the last run).
squaremo
changed the title
Deferred, file read, and filesystem API
Deferreds, file read, and filesystem API
Dec 3, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR
{name, path, isdir}
for an individual path.