Skip to content

Instantly share code, notes, and snippets.

@kriskowal
Created December 14, 2022 22:53
Show Gist options
  • Save kriskowal/daf5f7f084780373d687658bc941410a to your computer and use it in GitHub Desktop.
Save kriskowal/daf5f7f084780373d687658bc941410a to your computer and use it in GitHub Desktop.
const makeNearReader = reader =>
Far('Reader', {
async next() {
const iteration = await reader.next();
if (iteration.done) {
return iteration;
}
return harden({ value: encodeBase64(iteration.value) });
},
async return(value) {
return reader.return(value);
},
async throw(error) {
return reader.throw(error);
},
});
const makeFarReader = readerPresence => ({
async next(value) {
const result = await E(readerPresence).next(value);
if (result.done) {
return result;
}
return harden({ value: decodeBase64(result.value) });
},
async return(value) {
return E(readerPresence).return(value);
},
async throw(value) {
return E(readerPresence).throw(value);
},
[Symbol.asyncIterator]() {
return this;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment