Neek Sandhu (2018-07-17T06:26:00.000Z)
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`

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180717/583bd4bd/attachment.html>
neek.sandhu at outlook.com (2018-07-17T06:31:14.895Z)
Ok maybe you guys are not 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`