@bz0/bcom2 v2.4.0-a
❤️🔥 BCom v2.4 ❤️🔥
(Civet Edition)
Former
InterWork
orInterWork2
,IW2
. Renamed due of branding. Also I thinkBCom
would be better thanBInter
🗺 Motivation 🗺
I decided to write my own library inspired by Comlink or Coincident. Based mainly on the latest and modern EcmaScript standards. Last year's first version, released sometime in 2021 or 2022, was a big bump in the road. So I decided to rewrite the project... I decided that those libraries have some serious drawbacks, especially related to proxying. There may be other problems as well. I decided not to ask these offices to guide me to the right solution.
🐆 What a Civet edition? 🐆
It means, based on Civet-compatible (ES-mode) language. There also not so big bug-fixes, mostly syntax reworking. Planned also custom operators for lazy ops, or function context. In general, not so many difference from v2.3.
👷 Purpose 👷
IW2 - is multi-purpose WebWorker and WebSocket library.
You can
- Copy typed arrays between workers or sockets.
- Use proxy of DOM from Web (Worker or Socket).
- Use in image processing (by OffscreenCanvas).
- Transfer data between main and worker.
- Use for WebAssembly (uses sync ops).
- Use
SharedArrayBuffer
withAtomic
. - Acceleration or offload some hard tasks.
- Using remote function or class (i.e. module) as is.
⭐ Features ⭐
(Generated by Chad)
- Ease of use: IW2 offers a simple and intuitive API for creating, managing, and communicating with web workers.
- Data transmission: The library makes it easy to transmit complex objects and data between the main thread and workers.
- Remote function calls: IW2 allows for calling functions that execute in web workers by simply passing the function name and parameters.
- Message handling: The library provides a mechanism for conveniently handling and responding to messages received from web workers.
- Worker pooling: IW2 supports worker pooling, allowing for efficient utilization of available resources and management of worker creation and destruction.
- High performance: IW2 is optimized for data exchange between the main thread and web workers, providing fast message transmission and processing.
- Scalability: IW2 supports working with multiple web workers, allowing efficient resource utilization and distribution of tasks among them.
- Support for various message types: IW2 can handle different types of data, including text, numbers, objects, and arrays. This makes the library flexible and versatile for different use cases.
- Compatibility: IW2 is compatible with modern browsers that support web workers, such as Chrome, Firefox, and
Safari. - Fault tolerance: IW2 ensures reliable message transmission between the main thread and workers, handling possible errors and exceptions.
🚉 Platform support 🚉
Frontend
Chrome
/Edge
/Chromium
(experimental)Firefox
(tested on Nightly)
Backend
Deno
(experimental)Bun.js
(tested, no support ES6 mode)Node.js
(planned, delayed)
📚 Dependency 📚
🪁 Example 🪁
Wrapper examples
Browser (fastify)
<script type="importmap">
{
"imports": {
".": ".",
"cbor-x/": "/cbor-x/",
"cbor-x": "/cbor-x/index.js",
"@petamoriken/": "/@petamoriken/",
"@petamoriken/float16": "/@petamoriken/float16/browser/float16.mjs",
"src/": "/src/",
"test/": "/test/",
"deps/": "/deps/",
"BTyped2/": "/BTyped2/"
}
}
</script>
import IW from "src/index.mjs";
import { main } from "../worker/main.mjs";
//import { Worker, isMainThread, parentPort, workerData, } from 'node:worker_threads'
const $R = location?.href ?? Deno?.cwd?.();
const importMap = {
imports: {
".": `${$R}.`,
"cbor-x/": `${$R}cbor-x/`,
"cbor-x": `${$R}cbor-x/index.js`,
"@petamoriken/": `${$R}@petamoriken/`,
"@petamoriken/float16": `${$R}@petamoriken/float16/browser/float16.mjs`,
"src/": `${$R}src/`,
"test/": `${$R}test/`,
"deps/": `${$R}deps/`,
"BTyped2/": `${$R}BTyped2/`,
},
};
// get worker internal library
const worker = new Worker(
IW.WrapWorkerURL(
new URL("../worker/worker.mjs", import.meta.url).href,
importMap,
),
{
//type: "module",
deno: { permissions: "inherit" },
importMap: import.meta.importMap,
},
);
//
main(worker);
Deno
import IW from "src/index.mjs";
import { main } from "../worker/main.mjs";
// get worker internal library
const worker = new Worker(
IW.WrapWorkerURL(new URL("../worker/worker.mjs", import.meta.url).href),
{
type: "module",
deno: { permissions: "inherit" },
importMap: import.meta.importMap,
},
);
//
main(worker);
🤚 ShadowRealm... ✋
We waiting support for ShadowRealm in browsers!
ShadowRealm already available on Canary Chrome, Chromium daily and Firefox Nightly...
📦 Install 📦
Currently, available ways:
git submodule add https://github.com/BlazerNEO/BInter2.git deps/InterWork2
git clone https://github.com/BlazerNEO/BInter2.git --recursive
npm install
(for test)
📦 Projects 📦
- 🪖 BTyped2 🪖 - library for encoders and decoders, also for animations. "Required!"
- ❤️🔥 BInter2 ❤️🔥 - next-gen pure JS web worker library.
- 🥀 BQuery 🥀 - JQuery alternative, competitor, wrapper, library.
🗿 Standby... 🗿
7 months ago