Ok maybe you guys are impressed enough 😊

Here’s a 339 line file and [on Line 85 there’s a variable called 
`workerInitPromise`](https://github.com/NeekSandhu/v-thread/blob/ed350bd4dcbf8e368cea2b3819f405b61ef783a3/src/MainThread.ts#L85)

Only one method in that class is concerned with `workerInitPromise`, that is 
`startWorker()`

What is `workerInitPromise`?

Well, whenever 
[`startWorker()`](https://github.com/NeekSandhu/v-thread/blob/ed350bd4dcbf8e368cea2b3819f405b61ef783a3/src/MainThread.ts#L236)
 is called it should return a `Promise` that should resolve when the `Worker` 
is up and running.

That means one call to `startWorker` has started the worker startup sequence 
and it’d be wasteful to start it over again when someone else calls 
`startWorker`.

Instead `startWorker` decides to ā€œshareā€ the `Promise` amongst furious callers. 
Now, `startWorker` needs a place to store that `Promise` so he can share with 
subsequent callers.
Where is that place???

And that my friends is why I had to create `workerInitPromise` prop on the 
class, just to make `startWorker` happy.


It ā€œbelongsā€ in `startWorker` and should ā€œliveā€ inside `startWorker`

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to