Skip to content

Seamless async integration in JS library code #25970

@sbc100

Description

@sbc100

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.

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