Skip to content

Instantly share code, notes, and snippets.

View Megaemce's full-sized avatar

Megaemce

View GitHub Profile
@Megaemce
Megaemce / ExampleClass.ts
Last active May 25, 2024 07:52
Using web workers with Promises in a React + TypeScript project
export default class ExampleClass {
private someArray: string[] = ["A","B","C","D"];
// ...
/**
* Asynchronously executes a web worker example using an array of elements.
* Each element is processed by a web worker and the results are concatenated.
*
* @return {Promise<string>} A promise that resolves to a string containing the results of all web worker executions.
* @throws {Error} If there is an error in executing the web workers or if the worker returns an error.