-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
While reviewing #25523 it occurred to me that we should able to avoid the custom proxying code being added there.
When we have JS library functions such as select or poll (or even read and write) then can have optional blocking. i.e. They should be able "block" whenever they are called from a pthread.
The only time they cannot block is when they are called from the main thread (and we don't have JSPI or ASYNCIFY enabled).
Considering just the pthread/worker use case we should be able detect if that originator of the calls was a worker and return promise in the case.
e.g.
if (callerIsWorker) {
return new Promise(...);
} else {
return EWOULDBLOCK (or ENOSYS);
}
Perhaps we could extend the existing __async attribute to mean async where possible. These function could return a promise when its OK to do so (i.e. when proxied from a pthread) and return a value (i.e. EWOULDBLOCK) when run on the main thread.