Skip to content

Async function blocks other threads from executing? #196

@evandarcy

Description

@evandarcy

Calling a function like this in two separate threads will result in the second thread being blocked from running until first thread callback is hit.

var wrapper = async function(time, callback){`
    console.log('start');
    setTimeout(function(){
        console.log('end');
        callback('hit');
    }, time);
};
interpreter.setProperty(globalObject, 'await',
    interpreter.createAsyncFunction(wrapper));

If I call await(2000) in both threads and run them simultaneously, I expect to see 'start' printed simultaneously. Instead the first 'start' will be printed followed by 'end' and then the second 'start' will be printed.

Should it be possible in theory to achieve this? If so, any suggestions are appreciated! Perhaps I am approaching this from the wrong angle or there is a workaround I have not considered.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions