Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Streams introduce flakiness/random results #2

@jukowski

Description

@jukowski

I get flacky results when trying to read small files from my hard drive. Sometimes, when access to my harddrive is slow, I get the whole content of the small files. Other times, when content was cached by the OS, the Stream sends "data" events before my code gets to hook into them.

Here is the function I'm using to get the content:
{{{

loads file contents into a string

loadVFSFile = (path, _callback) ->
async.waterfall([
(callback) -> vfs.readfile(path, {encoding:'utf8'}, callback),
(meta, callback) ->
data = '';
meta.stream.on("data", (item) ->
data += item;
)
meta.stream.on("end", () ->
callback(null, data);
)
return;
], (err, data) ->
console.log(err, data);
_callback(err, data);
);
}}}
if I don't use async.waterfall then it works much better but it seems that I don't get any guaranty that it will always work...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions