Skip to content

async_wrap: when is callback ready to be called #11

Closed
@AndreasMadsen

Description

While developing dprof I came to realize that using beforeTimestamp (pre hook) - initTimestamp (init hook) as an async duration estimate is a bit misleading.

For example if user create a timeout of 100 ms and in the meanwhile have a cpu hungry calculation there takes 200 ms. The async operation only takes 100 ms but the beforeTimestamp - initTimestamp would indicate 200 ms.

A bit more likely, user could do fs.open which would finish quickly, but have so many other callbacks there needs calling first that it would take much longer time before the fs.open callback is called.

In both cases it would look like the async operation took much longer than it actually did. The user would ask questions like "why did my timeout take 200 ms, when I set it to 100 ms?" or "why is my filesystem so slow?".

I don't known if it is possible but I think a asyncReady event is missing. This would emit when the async operation is done. I'm guessing there is some interrupt causing a push the job queue that one could listen on, but I don't know. Emitting the event immediately would be problematic, as the javascript program would jump in a sync state. So I guess asyncReady it will just have to be executed right after the current callback is done. This would fix the fs.open example, but not the setTimeout example.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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