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

Is is possible to use 2 or more streams at once? #55

Open
benderlidze opened this issue Apr 30, 2020 · 0 comments
Open

Is is possible to use 2 or more streams at once? #55

benderlidze opened this issue Apr 30, 2020 · 0 comments
Labels

Comments

@benderlidze
Copy link

benderlidze commented Apr 30, 2020

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/[email protected]/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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants