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

Projects
None yet
6 participants
@addaleax
Copy link
Member

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
@nodejs-github-bot

This comment has been minimized.

@addaleax

This comment has been minimized.

Copy link
Member Author

commented Apr 24, 2019

@nodejs-github-bot

This comment has been minimized.

@benjamingr
Copy link
Member

left a comment

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

This comment has been minimized.

Copy link
Member Author

commented Apr 25, 2019

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

This comment has been minimized.

@addaleax addaleax force-pushed the addaleax:messageport-single-message branch from d4e82e4 to 248a203 May 14, 2019

@addaleax

This comment has been minimized.

Copy link
Member Author

commented May 14, 2019

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

@nodejs-github-bot

This comment has been minimized.

@benjamingr

This comment has been minimized.

Copy link
Member

commented May 14, 2019

Still lgtm

@nodejs-github-bot

This comment has been minimized.

@addaleax addaleax referenced this pull request May 14, 2019

Closed

worker: use special message as MessagePort close command #27705

3 of 3 tasks complete
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.

@addaleax addaleax force-pushed the addaleax:messageport-single-message branch from 248a203 to 8bd751a May 19, 2019

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@addaleax

This comment has been minimized.

Copy link
Member Author

commented May 19, 2019

Landed in 76f2168

@addaleax addaleax closed this May 19, 2019

@addaleax addaleax deleted the addaleax:messageport-single-message branch May 19, 2019

addaleax added a commit that referenced this pull request May 19, 2019

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.

PR-URL: #27294
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

targos added a commit that referenced this pull request May 20, 2019

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.

PR-URL: #27294
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

BridgeAR added a commit that referenced this pull request May 21, 2019

2019-05-21, Version 12.3.0 (Current)
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 referenced this pull request May 21, 2019

Merged

v12.3.0 proposal #27799

4 of 4 tasks complete

BridgeAR added a commit that referenced this pull request May 21, 2019

2019-05-21, Version 12.3.0 (Current)
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

2019-05-21, Version 12.3.0 (Current)
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
You can’t perform that action at this time.