Created
December 14, 2022 22:53
-
-
Save kriskowal/daf5f7f084780373d687658bc941410a to your computer and use it in GitHub Desktop.
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
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