All Projects β†’ duart38 β†’ Thread

duart38 / Thread

Licence: MIT license
type safe multi-threading made easier

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Thread

React Native Multithreading
🧡 Fast and easy multithreading for React Native using JSI
Stars: ✭ 164 (+382.35%)
Mutual labels:  thread, multithreading, threading
react-use-comlink
Three ways to use Comlink web workers through React Hooks (and in a typesafe manner).
Stars: ✭ 39 (+14.71%)
Mutual labels:  worker, webworker, webworkers
Microjob
A tiny wrapper for turning Node.js worker threads into easy-to-use routines for heavy CPU loads.
Stars: ✭ 1,985 (+5738.24%)
Mutual labels:  thread, multithreading, threading
ObviousAwait
🧡 Expressive aliases to ConfigureAwait(true) and ConfigureAwait(false)
Stars: ✭ 55 (+61.76%)
Mutual labels:  thread, multithreading, threading
Greenlet
🦎 Move an async function into its own thread.
Stars: ✭ 4,511 (+13167.65%)
Mutual labels:  worker, thread, webworker
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (+1420.59%)
Mutual labels:  worker, thread, multithreading
Workly
A really simple way to move a function or class to a web worker. πŸ‹οΈβ€β™€οΈβ†’ πŸ˜„
Stars: ✭ 1,848 (+5335.29%)
Mutual labels:  thread, webworker
Lightio
LightIO is a userland implemented green thread library for ruby
Stars: ✭ 165 (+385.29%)
Mutual labels:  thread, multithreading
Sobjectizer
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.
Stars: ✭ 172 (+405.88%)
Mutual labels:  thread, multithreading
Interlace
Easily turn single threaded command line applications into a fast, multi-threaded application with CIDR and glob support.
Stars: ✭ 760 (+2135.29%)
Mutual labels:  thread, multithreading
Java Concurrency Examples
Java Concurrency/Multithreading Tutorial with Examples for Dummies
Stars: ✭ 173 (+408.82%)
Mutual labels:  thread, multithreading
event-worker
A simpler way of dealing with Web Workers
Stars: ✭ 18 (-47.06%)
Mutual labels:  worker, thread
Pelagia
Automatic parallelization (lock-free multithreading thread) tool developed by Surparallel Open Source.Pelagia is embedded key value database that implements a small, fast, high-reliability on ANSI C.
Stars: ✭ 1,132 (+3229.41%)
Mutual labels:  thread, multithreading
Enkits
A permissively licensed C and C++ Task Scheduler for creating parallel programs. Requires C++11 support.
Stars: ✭ 962 (+2729.41%)
Mutual labels:  thread, multithreading
Thread Loader
Runs the following loaders in a worker pool
Stars: ✭ 945 (+2679.41%)
Mutual labels:  thread, multithreading
Task Worklet
Task Worklet: explainer, polyfill and demos.
Stars: ✭ 257 (+655.88%)
Mutual labels:  worker, threading
Alloy Worker
ι’ε‘δΊ‹εŠ‘ηš„ι«˜ε―η”¨ Web Worker ι€šδΏ‘ζ‘†ζžΆ
Stars: ✭ 349 (+926.47%)
Mutual labels:  worker, thread
Process
Creation of Dynamic Dedicated WebWorkers, definition of dependencies, promise support.
Stars: ✭ 13 (-61.76%)
Mutual labels:  thread, webworkers
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (+1929.41%)
Mutual labels:  thread, multithreading
tgrid
TypeScript Grid Computing Framework supporting RFC (Remote Function Call)
Stars: ✭ 83 (+144.12%)
Mutual labels:  worker, thread

alt text

nest badge alt text alt text alt text

  1. This module allows you to write Web Worker code inline with the rest of your code
  2. This module is also somewhat type safe
  3. Allows you to Thread already existing functions
  4. Allows module imports inside the worker

Examples

See examples folder for more examples

let thread = new Thread<number>((e: MessageEvent)=>{
    console.log('Worker: Message received from main script');
    const result = e.data[0] * e.data[1];
    if (isNaN(result)) {
      return 0;
    } else {
      console.log('Worker: Posting message back to main script');
      return(result);
    }
}, "module");

thread.onMessage((e)=>{
    console.log(`back from thread: ${e}`)
})
thread.postMessage([10, 12])

Instead of using the workers postMessage() method we return value from withing our method

Here's a few more examples

function someFunction(e: MessageEvent){
  return 0;
}

new Thread((e: MessageEvent)=>{return 0}, "module"); // inline Thread with return type of number
new Thread(someFunction, "module"); // thread an already existing function
new Thread(someFunction, "module", ['import Something from "../some.bundle.js";']); // thread with custom importing

Async support

const thread = new Thread<string, number>(async (_) => {
  console.log("Worker: Message received from main script");
  // Some async logic...
  await new Promise((ir) => setTimeout(ir, 2000));
  return "DONE";
}, "module");

thread.onMessage((e) => {
  console.log(`recived back from thread: ${e}`);
});

thread.postMessage(0);

API

Standard API

Method / variable Description
worker The Worker.
stopped Tells if the worker has been stopped
postMessage(msg) Sends data to the Thread
stop() calls terminate on the worker.
remove() Removes the current worker file from the temporary folder. NOTE: Can be used while the program is running (calls stop()..)
onMessage(callback: (e: T) =>void) Bind to the worker to receive messages
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].