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

Concurrent readFileFn calls tip #300

Open
drzraf opened this issue Jun 10, 2020 · 0 comments
Open

Concurrent readFileFn calls tip #300

drzraf opened this issue Jun 10, 2020 · 0 comments

Comments

@drzraf
Copy link
Collaborator

drzraf commented Jun 10, 2020

I'm reading from a stream instead of a blob I could slice.
In order to solve this problem, I had to implement a poor-man semaphore based on readState.

    async read(flowObj, startByte, endByte, fileType, chunk) {
        var prev_chunk = chunk.offset > 0 ? flowObj.chunks[chunk.offset - 1] : null;
        if (prev_chunk) {
            while(prev_chunk.readState != 2) {
                await new Promise(resolve => setTimeout(resolve, 500));
            }
        }
        flowObj.readState = 1;
        var blob = await this._reader.readFooBar();
        chunk.readFinished(blob);
    }

But I think a more elegant system could be built-in within flow.js.
Eg: streamRead: <boolean> : Set to true to avoid concurrent calls to read()
And readState could be made a Promise that readFinished resolves so that other chunks could await based on this promise completion status.

See also: #296 and #304

@drzraf drzraf changed the title Concurrent readFileFn Concurrent readFileFn calls tip Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant