Releasing thread and URL reference when the workerized function is not needed
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di developit/greenlet
-
support module workers? Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
_ref is not defined Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 30/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Tutte le issue di developit/greenlet
Issue simili
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Improve Title Support Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·