Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: add ability to unshift message from MessagePort #27294

Closed
wants to merge 1 commit into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Apr 18, 2019

worker: move receiving_messages_ field to MessagePort (landed as part of #27705)

This is a property of the native object associated with the
MessagePort, not something that should be set on the
conceptual MessagePort that may be transferred around.

(This is just cleanup that’s not directly related to the next commit except
for merge conflicts.)

worker: add ability to unshift message from MessagePort

In combination with Atomics, this makes it possible to implement
generic synchronous functionality, e.g. importScript(), in Workers
purely by communicating with other threads.

This is a continuation of #26686,
where a preference for a solution was voiced that allowed reading
individual messages, rather than emitting all messages through events.

(/cc @devsnek, @BridgeAR, @nodejs/workers)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@addaleax addaleax added semver-minor PRs that contain new features and should be released in the next minor version. worker Issues and PRs related to Worker support. labels Apr 18, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Apr 18, 2019
@addaleax
Copy link
Member Author

Ping @nodejs/workers

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual code LGTM the two concerns I have is:

  • Wouldn't it be better to provide an API that makes the ports AsyncIterable instead of adding this?
  • Are we OK adding this given there is no equivalent?

Actual code LGTM and if you find it useful I'm good with it.

@addaleax
Copy link
Member Author

Wouldn't it be better to provide an API that makes the ports AsyncIterable instead of adding this?

@benjamingr I think that async interation is of limited usefulness for APIs that refer to external events, like messages from another thread… but I wouldn’t mind making EventEmitter APIs AsyncIterable in general, similar to the API we have for readline.

Are we OK adding this given there is no equivalent?

You mean, no browser equivalent? I’m personally okay with that, yes – if we don’t want this, that’s okay, but I’d still prefer to make some way of transferring arbitrary data synchronously possible.

chjj added a commit to chjj/bthreads that referenced this pull request Apr 30, 2019
@nodejs-github-bot
Copy link
Collaborator

@addaleax addaleax force-pushed the messageport-single-message branch from d4e82e4 to 248a203 Compare May 14, 2019 12:13
@addaleax
Copy link
Member Author

Got around to fixing CI for this, had to revert a bit of the last commit.

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 14, 2019
@nodejs-github-bot
Copy link
Collaborator

@benjamingr
Copy link
Member

Still lgtm

@nodejs-github-bot
Copy link
Collaborator

In combination with Atomics, this makes it possible to implement
generic synchronous functionality, e.g. `importScript()`, in Workers
purely by communicating with other threads.

This is a continuation of nodejs#26686,
where a preference for a solution was voiced that allowed reading
individual messages, rather than emitting all messages through events.
@addaleax addaleax force-pushed the messageport-single-message branch from 248a203 to 8bd751a Compare May 19, 2019 12:46
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member Author

Landed in 76f2168

@addaleax addaleax closed this May 19, 2019
@addaleax addaleax deleted the messageport-single-message branch May 19, 2019 20:10
addaleax added a commit that referenced this pull request May 19, 2019
In combination with Atomics, this makes it possible to implement
generic synchronous functionality, e.g. `importScript()`, in Workers
purely by communicating with other threads.

This is a continuation of #26686,
where a preference for a solution was voiced that allowed reading
individual messages, rather than emitting all messages through events.

PR-URL: #27294
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this pull request May 20, 2019
In combination with Atomics, this makes it possible to implement
generic synchronous functionality, e.g. `importScript()`, in Workers
purely by communicating with other threads.

This is a continuation of #26686,
where a preference for a solution was voiced that allowed reading
individual messages, rather than emitting all messages through events.

PR-URL: #27294
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
BridgeAR added a commit that referenced this pull request May 21, 2019
Notable changes:

* process:
  * Log errors using `util.inspect` in case of fatal exceptions
    (Ruben Bridgewater) #27243
* repl:
  * Add `process.on('uncaughtException')` support (Ruben Bridgewater)
    #27151
* stream:
  * Implemented `Readable.from` async iterator utility (Guy Bedford)
    #27660
* tls:
  * Expose built-in root certificates (Ben Noordhuis)
    #26415
  * Support `net.Server` options (Luigi Pinca)
    #27665
  * Expose `keylog` event on TLSSocket (Alba Mendez)
    #27654
* worker:
  * Added the ability to unshift messages from the `MessagePort`
    (Anna Henningsen) #27294
@BridgeAR BridgeAR mentioned this pull request May 21, 2019
4 tasks
BridgeAR added a commit that referenced this pull request May 21, 2019
Notable changes:

* esm:
  * Added the `--experimental-wasm-modules` flag to support
    WebAssembly modules (Myles Borins & Guy Bedford)
    #27659
* process:
  * Log errors using `util.inspect` in case of fatal exceptions
    (Ruben Bridgewater) #27243
* repl:
  * Add `process.on('uncaughtException')` support (Ruben Bridgewater)
    #27151
* stream:
  * Implemented `Readable.from` async iterator utility (Guy Bedford)
    #27660
* tls:
  * Expose built-in root certificates (Ben Noordhuis)
    #26415
  * Support `net.Server` options (Luigi Pinca)
    #27665
  * Expose `keylog` event on TLSSocket (Alba Mendez)
    #27654
* worker:
  * Added the ability to unshift messages from the `MessagePort`
    (Anna Henningsen) #27294

PR-URL: #27799
BridgeAR added a commit that referenced this pull request May 21, 2019
Notable changes:

* esm:
  * Added the `--experimental-wasm-modules` flag to support
    WebAssembly modules (Myles Borins & Guy Bedford)
    #27659
* process:
  * Log errors using `util.inspect` in case of fatal exceptions
    (Ruben Bridgewater) #27243
* repl:
  * Add `process.on('uncaughtException')` support (Ruben Bridgewater)
    #27151
* stream:
  * Implemented `Readable.from` async iterator utility (Guy Bedford)
    #27660
* tls:
  * Expose built-in root certificates (Ben Noordhuis)
    #26415
  * Support `net.Server` options (Luigi Pinca)
    #27665
  * Expose `keylog` event on TLSSocket (Alba Mendez)
    #27654
* worker:
  * Added the ability to unshift messages from the `MessagePort`
    (Anna Henningsen) #27294

PR-URL: #27799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants