Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Releasing thread and URL reference when the workerized function is not needed

Aperta
#49 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
web-dev

Direzione di ricerca

Inizia dal codice sorgente relativo alla creazione di workerURL e alla chiamata a new Worker, quindi confrontalo con l’esempio nel README che usa greenlet. Determina se la funzione restituita debba esporre una modalità di rilascio e quale pulizia o comportamento successivo al rilascio sia richiesto. Il lavoro è completato quando la decisione sul ciclo di vita della risorsa è implementata in modo coerente con l’API proposta.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Great library, very useful stuff and absolutely love the size. :)

I've only recently started learning about Web Workers and took a look at the source code. So apologies in advance if I am wrong ;). 2 things caught my eyes:

const workerURL = URL.createObjectURL(new Blob([script]));
// Create an "inline" worker (1:1 at definition time)
const worker = new Worker(workerURL);

So if we do something like the following snippet (taken from the README), it seems that each new function instantiated via greenlet(...) will reserve a new thread and a new URL reference.

import greenlet from 'greenlet'

let getName = greenlet( async username => {
    let url = `https://api.github.com/users/${username}`
    let res = await fetch(url)
    let profile = await res.json()
    return profile.name
})

console.log(await getName('developit'))

So, if there is a case wherein I don't need to use getName after a certain point in my code, those resources are still trapped. They may be very less in size to be of a practical concern, but I am not sure about it and would love if anyone can comment on that.

However, if the output function getName comes with a dispose method which releases those references, it could be useful. WDYT? Something like:

getName.dispose() // Release references 

Internally, it could call:

window.URL.revokeObjectURL(workerURL);
worker.terminate();

Post dispose, getName can itself become undefined so it's not callable. Or can throw a more informative error: The function is disposed/discarded due to .dispose() call..

Is there a downside to this approach if the contributors already considered any similar approach?

Lingua principale
JavaScript
Stelle
4.7k
Fork
97
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di developit/greenlet

Tutte le issue di developit/greenlet

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.