Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

Clooney

Clooney is an actor (ayooo) library for the web. Classes given to Clooney will be instantiated and run in a worker, keeping the main thread responsive.

⚠️ Caveat: The class cannot rely on its surrounding scope, since it is executed in an isolated context. This might change once workers support ES6 modules.

Quickstart

An example says more than 1000 words:

<script src="https://raw.githubusercontent.com/GoogleChromeLabs/clooney/master/clooney.bundle.js"></script>
<script>
  (async function() {
    class MyRemoteClass {
      doExpensiveCalculation(a, b) {
        return a + b;
      }
    }

    const instance = await Clooney.spawn(MyRemoteClass);
    console.log(await instance.doExpensiveCalculation(5, 23));
  })();
</script>

I’m collecting more examples of Clooney in action in this Glitch.

Browser support

Clooney uses Comlink under the hood, and so inherits its browser compatibility matrix.

Chrome 56+ Edge 15+ Firefox 52+ Opera 43+ Safari 10.1+ Samsung Internet 6.0+

Browsers without ES6 Proxy support can use the proxy-polyfill.

Events and Functions

Functions and events are not transferable (i.e. can’t be sent from to a worker), but Clooney has special handling for them:

class MyRemoteClass {
  onClick(remoteEvent) {
    // … react to click …
  }
}

const instance = await Clooney.spawn(MyRemoteClass);
const button = document.querySelector('button');
button.addEventListener('click', instance.onClick.bind(instance));

The remoteEvent object is a mangled version of the original event to make it transferable:

const remoteEvent = {
  targetId, // = event.target.id
  targetClassList, // = [...event.target.classList]
  detail, // = event.detail
  data // = event.data
};

Promises and async methods

Clooney handles promises (and therefore, async methods) automatically:

class Actor {
  timeoutThing() {
    return new Promise(resolve => setTimeout(_ => resolve('ohai'), 1000));
  }
}

const instance = await strategy.spawn(Actor);
alert(await instance.timeoutThing()); // Will alert() after 1 second

API

Clooney’s job is to take actors (class definitions) and spawn those actors in containers (Web Workers). You can use that instance as if it was a local instance (this is magic provided by Comlink).

Clooney.spawn(class, constructorArgs)

This call is equivalent to Clooney.defaultStrategy.spawn(class, constructorArgs). Clooney creates an instance of RoundRobinStrategy as the default strategy.

Strategies

Strategies decide how many containers are spun up and where a new instance is created.

export interface Strategy {
  /**
   * `spawn` instantiates the given actor in an actor container of the strategy’s choice.
   * @returns The return type is the type as T, but every method is implicitly async.
   */
  spawn<T>(actor: new () => T, constructorArgs: any[], opts: Object): Promise<T>;
  /**
   * `terminate` calls `terminate()` on all existing containers of the strategy.
   */
  terminate(): Promise<void>;
}

Clooney.RoundRobinStrategy(opts)

RoundRobinStrategy creates up to n containers and cycles through the containers with every spawn call. RoundRobinStrategy is the default strategy.

Strategy Options

  • maxNumContainers: Maximum number of containers to create (default: 1)
  • newWorkerFunc: Asynchronous function that creates a new container (default: new Worker(Clooney.defaultWorkerSrc))

Clooney.asRemoteValue(obj)

asRemoteValue marks a value. If a marked value is used as an parameter or return value, it will not be transferred but instead proxied.

CDN

If you want to use Clooney from a CDN, you need to work around the same-origin restrictions that workers have:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/clooney.bundle.min.js"></script>
<script>
  async function newWorkerFunc() {
    const blob = await fetch(Clooney.defaultWorkerSrc).then(resp => resp.blob())
    return new Worker(URL.createObjectURL(blob));
  }

  const strategy = new Clooney.RoundRobinStrategy({newWorkerFunc});
  // Business as usual using strategy.spawn() ...
</script>

License Apache-2.0

JavaScript
JavaScript
JavaScript is a dynamic scripting language used to create interactive web experiences. It's an essential tool for front-end development, enabling features like dynamic content, animations, and event handling. JavaScript is supported by all major browsers.
GitHub - dalekjs/dalek: [unmaintained] DalekJS Base framework
GitHub - dalekjs/dalek: [unmaintained] DalekJS Base framework
Tabulator - Interactive JavaScript Tables
Tabulator - Interactive JavaScript Tables
GitHub - totorojs/totoro: A simple and stable cross-browser testing tool. 简单稳定的跨浏览器测试工具。
GitHub - totorojs/totoro: A simple and stable cross-browser testing tool. 简单稳定的跨浏览器测试工具。
GitHub - duojs/duo: A next-generation package manager for the front-end
GitHub - duojs/duo: A next-generation package manager for the front-end
GitHub - hakimel/reveal.js: The HTML Presentation Framework
GitHub - hakimel/reveal.js: The HTML Presentation Framework
PixiJS | The HTML5 Creation Engine | PixiJS
PixiJS | The HTML5 Creation Engine | PixiJS
GitHub - adonisjs/core: AdonisJS is a TypeScript-first web framework for building web apps and API servers. It comes with support for testing, modern tooling, an ecosystem of official packages, and more.
GitHub - adonisjs/core: AdonisJS is a TypeScript-first web framework for building web apps and API servers. It comes with support for testing, modern tooling, an ecosystem of official packages, and more.
GitHub - os-js/OS.js: OS.js - JavaScript Web Desktop Platform
GitHub - os-js/OS.js: OS.js - JavaScript Web Desktop Platform
GitHub - alpinejs/alpine: A rugged, minimal framework for composing JavaScript behavior in your markup.
GitHub - alpinejs/alpine: A rugged, minimal framework for composing JavaScript behavior in your markup.
Phaser - A fast, fun and free open source HTML5 game framework
Phaser - A fast, fun and free open source HTML5 game framework
GitHub - chaijs/chai: BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
GitHub - chaijs/chai: BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
GitHub - simplegeo/polymaps: Polymaps is a free JavaScript library for making dynamic, interactive maps in modern web browsers.
GitHub - simplegeo/polymaps: Polymaps is a free JavaScript library for making dynamic, interactive maps in modern web browsers.
List.js
List.js
GitHub - pchen66/panolens.js: Javascript panorama viewer based on Three.js
GitHub - pchen66/panolens.js: Javascript panorama viewer based on Three.js
GitHub - Fooidge/PleaseJS: JavaScript Library for creating random pleasing colors and color schemes
GitHub - Fooidge/PleaseJS: JavaScript Library for creating random pleasing colors and color schemes
GitHub - canjs/canjs: Build CRUD apps in fewer lines of code.
GitHub - canjs/canjs: Build CRUD apps in fewer lines of code.
GitHub - blueimp/jQuery-File-Upload: File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.
GitHub - blueimp/jQuery-File-Upload: File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.
GitHub - peachananr/onepage-scroll: Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin
GitHub - peachananr/onepage-scroll: Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin
FoalTS
FoalTS
GitHub - whatsup/whatsup: A frontend framework for chillout-mode development 🥤 JSX components on generators*, fast mobx-like state management and exclusive cssx style system
GitHub - whatsup/whatsup: A frontend framework for chillout-mode development 🥤 JSX components on generators*, fast mobx-like state management and exclusive cssx style system
GitHub - gka/chroma.js: JavaScript library for all kinds of color manipulations
GitHub - gka/chroma.js: JavaScript library for all kinds of color manipulations
Matter.js
Matter.js
GitHub - guillaumepotier/Parsley.js: Validate your forms, frontend, without writing a single line of javascript
GitHub - guillaumepotier/Parsley.js: Validate your forms, frontend, without writing a single line of javascript
GitHub - pegjs/pegjs: PEG.js: Parser generator for JavaScript
GitHub - pegjs/pegjs: PEG.js: Parser generator for JavaScript
GitHub - qTip2/qTip2: qTip2 - Pretty powerful tooltips
GitHub - qTip2/qTip2: qTip2 - Pretty powerful tooltips
GitHub - nightwatchjs/nightwatch: Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
GitHub - nightwatchjs/nightwatch: Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
GitHub - chartjs/Chart.js: Simple HTML5 Charts using the <canvas> tag
GitHub - chartjs/Chart.js: Simple HTML5 Charts using the <canvas> tag
GitHub - ariya/phantomjs: Scriptable Headless Browser
GitHub - ariya/phantomjs: Scriptable Headless Browser
GitHub - keystonejs/keystone: The superpowered headless CMS for Node.js — built with GraphQL and React
GitHub - keystonejs/keystone: The superpowered headless CMS for Node.js — built with GraphQL and React
AnyChart is a lightweight and robust JavaScript charting library
AnyChart is a lightweight and robust JavaScript charting library
JavaScript
More on JavaScript

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.