Skip to content

Share a function between threads in pool #6527

Answered by AriPerkkio
RobinTail asked this question in Q&A
Discussion options

You must be logged in to vote

VITEST_POOL_ID will be unique on each test runner thread so you can use that to derive unique numbers. Other solutions could be to create small HTTP or websocket server where you could fetch the port number. Or read it from file system - but that could run into race conditions when there's no locking system used.

Internally Vitest uses node:worker_thread's communication channel, but we don't expose it to users in any way. I've seen requests like this before, so I'm starting to think if we should provide a way for users to call main thread from test runner threads. 🤔

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AriPerkkio
Comment options

Answer selected by RobinTail
@AriPerkkio
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants