Skip to content
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 15 commits into from
Dec 3, 2018
Merged

Conversation

squaremo
Copy link
Member

@squaremo squaremo commented Nov 27, 2018

This PR

  • adds a protocol for dealing with deferred values (those which will be supplied at some later date).
  • adds a built-in for reading the content of a file
  • adds built-ins for getting a directory listing and (less usefully perhaps) getting {name, path, isdir} for an individual path.

@squaremo squaremo changed the title WIP I/O system [WIP] I/O system Nov 27, 2018
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 :-)
@squaremo squaremo mentioned this pull request Nov 29, 2018
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 squaremo changed the title [WIP] I/O system Deferred, file read, and filesystem API Dec 3, 2018
@squaremo squaremo changed the title Deferred, file read, and filesystem API Deferreds, file read, and filesystem API Dec 3, 2018
@squaremo squaremo merged commit f24fdd3 into jkcfg:master Dec 3, 2018
@squaremo squaremo deleted the io branch March 11, 2020 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant