[HN Gopher] Comlink Makes WebWorkers Enjoyable
       ___________________________________________________________________
        
       Comlink Makes WebWorkers Enjoyable
        
       Author : thunderbong
       Score  : 45 points
       Date   : 2023-08-07 16:42 UTC (6 hours ago)
        
 (HTM) web link (www.npmjs.com)
 (TXT) w3m dump (www.npmjs.com)
        
       | throwaway290 wrote:
       | Can it run untrusted worker code in "sandbox iframe" mode?
       | Something like jailed. Or do these both go together?
        
         | cyanydeez wrote:
         | I'd not trust anyt webworkers as a jail.
         | 
         | Look into quickjs if you want untrusted JavaScript in the
         | browser.
         | 
         | A quick read suggests it's note wiring iframe comes which
         | requires another abstractions.
        
       | DylanSp wrote:
       | Interesting. Question due to unfamiliarity - how reliable are Web
       | Workers? If the main UI thread is up and running, is it safe to
       | assume that any created workers are also running and able to
       | receive/send messages?
        
         | cyanydeez wrote:
         | Think of webworkers as forked subprocesses. You can create them
         | from a script interact, then kill them.
         | 
         | They're basically the future of any serious web first PWA where
         | you're not even concerned about a server doing anything.
        
       | mrloop wrote:
       | Used Comlink for a small toy project and made it really easy with
       | very little change to move an expensive file merge off the main
       | thread and do it in the background. Next time I use WebWorkers
       | I'll probably use Comlink.
       | 
       | Example of using here https://github.com/mrloop/activity-
       | merge/blob/main/app/contr...
        
       | kipple wrote:
       | I've used Comlink in a production React app (for client-side text
       | search) and enjoyed it.
       | 
       | The lib author wrote a nice blog post about "why webworkers" and
       | "why comlink" a few years ago: https://surma.dev/things/when-
       | workers/
        
       | emadda wrote:
       | One alternative to Comlink is to use IndexedDB transactions and
       | polling.
       | 
       | IndexedDB can be shared amongst Web Workers for the same origin
       | (localStorage cannot).
       | 
       | https://dexie.org is a nice IndexedDB library.
       | 
       | As an example, if you have many web workers, each can write their
       | current state or use transactions to take items from a queue, and
       | a central UI can just query the single IndexedDB.
        
         | moritzwarhier wrote:
         | Wow, I had no idea about this! What do you think is the current
         | state of adoption for IndexedDB apart from fingerprinting?
        
           | emadda wrote:
           | I'm not sure to be honest, https://caniuse.com/indexeddb
           | lists >95% for browser implementations.
           | 
           | I quite like IndexedDB as it is widely supported by browsers.
           | 
           | Although for simple data I prefer the sync localStorage API.
        
             | moritzwarhier wrote:
             | It's the same for me! sessionStorage is handy as well for
             | things like autocomplete result caching. Was wondering
             | about adoption in usage, not implementation.
        
       ___________________________________________________________________
       (page generated 2023-08-07 23:01 UTC)