-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Labels
Description
Here is an example. I am getting messed data with this script. Some part on data from ndjson1.json is in mainD2 and vice versa. Is this a bug or it is impossible to use 2 or more streams at once?
<script src='https://unpkg.com/can-ndjson-stream@1.0.2/dist/global/can-ndjson-stream.js'></script>
<script>
const streamerr = e => {
console.warn("Stream error");
console.warn(e);
}
const mainD1 = [];
const mainD2 = [];
fetch("ndjson1.json").then((response) => {
return can.ndjsonStream(response.body);
}).then(todosStream => {
var reader = todosStream.getReader();
reader.read().then(read = result => {
if (result.done) {
console.log("Done.");
return;
}
mainD1.push(result.value);
reader.read().then(read, streamerr);
}, streamerr);
});
fetch("ndjson2.json").then((response) => {
return can.ndjsonStream(response.body);
}).then(todosStream => {
var reader = todosStream.getReader();
reader.read().then(read = result => {
if (result.done) {
console.log("Done.");
return;
}
mainD2.push(result.value);
reader.read().then(read, streamerr);
}, streamerr);
});
</script>