All Projects → Wildhoney → Freelancer

Wildhoney / Freelancer

Licence: gpl-3.0
👔 An implementation of on-the-fly defined WebWorkers that are created inline using data URIs, rather than separate physical files — for the benefit of all humanity.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Freelancer

Concurrent
concurrency utilities
Stars: ✭ 186 (+226.32%)
Mutual labels:  concurrency, concurrent
practice
Java并发编程与高并发解决方案:http://coding.imooc.com/class/195.html Java开发企业级权限管理系统:http://coding.imooc.com/class/149.html
Stars: ✭ 39 (-31.58%)
Mutual labels:  concurrency, concurrent
Util
A collection of useful utility functions
Stars: ✭ 201 (+252.63%)
Mutual labels:  concurrency, concurrent
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+238.6%)
Mutual labels:  concurrency, concurrent
Zio
ZIO — A type-safe, composable library for async and concurrent programming in Scala
Stars: ✭ 3,167 (+5456.14%)
Mutual labels:  concurrency, concurrent
Tascalate Concurrent
Implementation of blocking (IO-Bound) cancellable java.util.concurrent.CompletionStage and related extensions to java.util.concurrent.ExecutorService-s
Stars: ✭ 144 (+152.63%)
Mutual labels:  concurrency, concurrent
Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.
Stars: ✭ 94 (+64.91%)
Mutual labels:  concurrency, concurrent
Goconcurrentqueue
Go concurrent-safe, goroutine-safe, thread-safe queue
Stars: ✭ 127 (+122.81%)
Mutual labels:  concurrency, concurrent
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (-70.18%)
Mutual labels:  concurrency, concurrent
treap
A thread-safe, persistent Treap (tree + heap) for ordered key-value mapping and priority sorting.
Stars: ✭ 23 (-59.65%)
Mutual labels:  concurrency, concurrent
java-multithread
Códigos feitos para o curso de Multithreading com Java, no canal RinaldoDev do YouTube.
Stars: ✭ 24 (-57.89%)
Mutual labels:  concurrency, concurrent
Hamsters.js
100% Vanilla Javascript Multithreading & Parallel Execution Library
Stars: ✭ 517 (+807.02%)
Mutual labels:  concurrency, concurrent
Libconcurrent
©️ Concurrent Programming Library (Coroutine) for C11
Stars: ✭ 335 (+487.72%)
Mutual labels:  concurrency, concurrent
Arq
Fast job queuing and RPC in python with asyncio and redis.
Stars: ✭ 695 (+1119.3%)
Mutual labels:  concurrency, concurrent
Elixirbooks
List of Elixir books
Stars: ✭ 1,021 (+1691.23%)
Mutual labels:  concurrent
Portable concurrency
Portable implementation of future/promise API in C++
Stars: ✭ 48 (-15.79%)
Mutual labels:  concurrency
Eventlet
Concurrent networking library for Python
Stars: ✭ 1,003 (+1659.65%)
Mutual labels:  concurrency
Routine
go routine control, abstraction of the Main and some useful Executors.如果你不会管理Goroutine的话,用它
Stars: ✭ 40 (-29.82%)
Mutual labels:  concurrent
S3 Lambda
Lambda functions over S3 objects with concurrency control (each, map, reduce, filter)
Stars: ✭ 1,061 (+1761.4%)
Mutual labels:  concurrency
Arpx
Automate and relate multiple processes.
Stars: ✭ 49 (-14.04%)
Mutual labels:  concurrency

Freelancer

npm i freelancer --save

An implementation of on-the-fly defined WebWorkers that are created inline using data URIs, rather than separate physical files — for the benefit of all humanity.

example: heroku   •   ~500 bytes gzipped.

Travis   npm   License MIT

Getting Started

Freelancer uses the same interface as Worker except the passed parameters upon instantiation are slightly different.

Normally when invoking new Worker you pass the location of the file, whereas with new Freelancer you pass a function that contains the body of the worker.

Freelancer also allows an optional second parameter to be passed that allows you to send additional options to the worker.

import { Freelancer } from 'freelancer';

const worker = new Freelancer(() => {
   
    self.addEventListener('message', event => {
        console.log(event.data);
        self.postMessage('Pong!');
    });
    
});

worker.addEventListener('message', event => console.log(event.data));
worker.postMessage('Ping?');

It's worth bearing in mind that the worker is still a separate thread and thus the typical rules of closures no longer apply – any parameters you would like to be received by the worker would need to be sent using postMessage or by passing parameters upon instantiation.

Passing Parameters

Upon instantiation of Freelancer you can use the second parameter to pass options that will be pushed to the worker – passed options will be serialized using JSON.stringify and thus any data sent needs to be serializable – which essentially means you're unable to pass by reference, and circular references will cause issues.

import { SharedFreelancer } from 'freelancer';

const options = { send: 'Ping?', respond: 'Pong!' };

const worker = new SharedFreelancer(options => {
   
    self.addEventListener('message', event => {
        console.log(event.data);
        self.postMessage(options.respond);
    });
    
}, options);

worker.addEventListener('message', event => console.log(event.data));
worker.postMessage(options.send);

Although we refer to it as the second parameter you are in fact able to pass an infinite amount of parameters to the worker – the only requirement is that the first parameter is the worker's function.

Dynamic Imports

When defining a worker inline you'll lose the ability to import because the declaration needs to be at the top-level – instead you should prefer dynamic imports using async functions or a simple Promise.then.

import { Freelancer } from 'freelancer';
import translate from './translator';

const worker = new Freelancer(async () => {
   
    const translate = await import('./translator');
    
    self.addEventListener('message', event => {
        self.postMessage(translate(options.respond));
    });
    
});

worker.postMessage(translate(options.send));

Unsupported Worker

In some cases SharedWorker — or to a lesser extent Worker — may be undefined due to a lack of browser support (see issue). When a worker is unsupported you'll receive an error message, and thus it's crucial to determine browser support before using a particular worker.

forthebadge

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].