A coincident Web world

Andrea Giammarchi
3 min readJul 4, 2023

--

The meaning of coincident

I don’t know if you read my Atomics and SharedArrayBuffer recent post (you should) but to me that was a journey to connect the dots and coincident is the child of such journey.

Goodbye Comlink

As written on the top of their README

> Comlink makes WebWorkers enjoyable …

Comlink presentation example

… and maybe it does, but there’s now an even more enjoyable way to write Web Workers code, one that doesn’t require you to expose(...) any namespace, and most importantly, one that doesn’t require you to await new MyClass() out there, or await instance.logSomething() neither, it’s called coincident.

Flipping the table!

The “funny” thing about Comlink is that it delegates to the main thread more tasks and code-paths (as in: we need to write unnatural code) in the name of making the Web non-blocking, so that the main thread has to do more to accommodate an already non-blocking resource as a Worker is … this is one of the reasons I’ve created tons of alternatives that, without Google marketing and brand name behind my shoulders, wouldn’t compete ever, but in Comlink: the main is the one doing more job than the worker, so that the worker can just push forward heavy computation as results but the main is in charge of lazily awaiting any of that, instead of being just available whenever results are ready.

Enough “blah-blah” though, what coincident does is to 100% allow any worker, non-blocking by nature, to perform any operation on the realm it’d like to operate, being that the main thread (UI/DOM/localStorage/anything else) or, as of today, a NodeJS or Bun server thread/process: you read it right, the Worker is the master, the rest are puppets, not the other way around!

Endless Possibilities

Remember the Electron issues with modules usable on the server but no on the user facing electron logic? Gone! Full server access on demand, if needed!

KIOSK like application that needed Electron to work? Gone, this stuff works on WPEWebkit too, and we all know that’s the browser any RaspberryPi KIOSK deserves for speed, memory, and performance sake.

A Tauri based application that does much more providing an Electron like App? You got it!

The list goes on … here we have a Worker literally able to drive, expose, or consume, anything the main world, or the server one, has to offer!

coincident/server running locally

The coincident module can now literally take over any page or backend without needing await or without needing anything Comlink required before, making you (me at least) writing code for the target you’d write code for, no expose(...), no Cmlink.wrap, no await needed, not for classes, not for references of any other kind, no Symbol limitation … nothing!

Wanna know more? Most progress has been explained in here, but feel free to reach me out to know more!

--

--

Andrea Giammarchi
Andrea Giammarchi

Written by Andrea Giammarchi

Web, Mobile, IoT, and all JS things since 00's. Formerly JS engineer at @nokia, @facebook, @twitter.

Responses (2)