Skip to content

Conversation

@jasnell
Copy link
Member

@jasnell jasnell commented Feb 23, 2021

The worker.platformData and worker.setPlatformData() APIs allow an arbitrary, cloneable JavaScript value to be set and passed to all new Worker instances spawned from the current context. It is similar to workerData except that platformData is set independently of the new Worker() constructor, and the value is passed automatically to all new Workers.

This is a partial fix of #30992
but does not implement a complete fix.

Signed-off-by: James M Snell [email protected]

/cc @addaleax @coreyfarrell

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 23, 2021
@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to Worker support. label Feb 23, 2021
@devsnek
Copy link
Member

devsnek commented Feb 23, 2021

lgtm with the global issue solved. Corey's proposed solution seems workable but still kind of unfortunate.

@Trott
Copy link
Member

Trott commented Feb 23, 2021

Would it make sense to implement this as experimental so we have some flexibility to tinker for the first few patch/minor releases?

@jasnell
Copy link
Member Author

jasnell commented Feb 23, 2021

We could get by with making platformData a Map to achieve the result. And yes, experimental is fine too start.

@addaleax
Copy link
Member

Since this works a lot like process.env except for non-string-data, maybe the name could also reflect that, because environment variables are something that developers probably tend to be more familiar with than the details of Workers?

@jasnell
Copy link
Member Author

jasnell commented Feb 23, 2021

Since this works a lot like process.env except for non-string-data, maybe the name could also reflect that, because environment variables are something that developers probably tend to be more familiar with than the details of Workers?

My only concern there would be developers mistaking it for environment variables. Hmm... perhaps setEnvironmentData()?

@nodejs-github-bot
Copy link
Collaborator

@jasnell
Copy link
Member Author

jasnell commented Feb 23, 2021

@coreyfarrell @addaleax @Trott @devsnek .. updated! Please take another look

Copy link
Member

@coreyfarrell coreyfarrell left a comment

Choose a reason for hiding this comment

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

This looks good, I think it will work for nyc once combined with the ability to inject code to run before the workers main script.

@jasnell jasnell force-pushed the worker-platform-data branch from a4ded12 to ebb9628 Compare March 1, 2021 17:57
@jasnell jasnell force-pushed the worker-platform-data branch from ebb9628 to b40c8f7 Compare March 11, 2021 17:21
These APIs allow arbitrary, cloneable JavaScript values to be set and
passed to all new Worker instances spawned from the current context.
It is similar to `workerData` except that environment data is set
independently of the `new Worker()` constructor, and the the value is
passed automatically to all new Workers.

This is a *partial* fix of nodejs#30992
but does not implement a complete fix.

Signed-off-by: James M Snell <[email protected]>
@jasnell jasnell force-pushed the worker-platform-data branch from b40c8f7 to 4f3f0f4 Compare March 11, 2021 17:43
@jasnell
Copy link
Member Author

jasnell commented Mar 11, 2021

@addaleax @coreyfarrell @gireeshpunathil ... alrighty! Updated! Please take a look.

@nodejs-github-bot

This comment has been minimized.

@jasnell jasnell added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 11, 2021
@jasnell

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Mar 11, 2021

@jasnell
Copy link
Member Author

jasnell commented Mar 15, 2021

Landed in 802b3e7

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. 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.

8 participants