Created
December 21, 2017 12:45
-
-
Save jooyunghan/3aa58ca5f8808c1211c62b65226a01eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async function* createAsyncIterator() { | |
const promise = []; | |
const values = []; | |
const subscription = this.materialize().subscribe(value => { | |
values.push(value); | |
promise.splice(0).forEach(r => r()); | |
}); | |
try { | |
while (true) { | |
while (values.length > 0) { | |
const v = values.shift(); | |
if (v.kind == 'N') yield v.value; | |
else if (v.kind == 'C') return; | |
else if (v.kind == 'E') throw v.error; | |
} | |
await new Promise(r => promise.push(r)); | |
} | |
} finally { | |
subscription.unsubscribe(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment