javascript-tutorial / javascript-tutorial/en.javascript.info

Suggestion for Additions to Article on Promise

Aperta
#2,807 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
HTML
Stelle
25.5k
Fork
4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

We can add a section for Promises vs Callbacks to show the inherent advantages of Promise:

Like this :

At the simplest level, Promises are just a different way of working with callbacks. However, there are practical benefits to using them.

  1. One real problem with callback based asynchronous programming is that it is common to end up with callbacks
    inside callbacks inside callbacks
    , with lines of code so highly indented that it is difficult to read.
    Promises allow this kind of nested callback to be re-expressed as a more linear Promise chain that tends to be easier to read and easier to reason about.

  2. Another problem with callbacks is that they can make handling errors difficult. If an asynchronous function (or an asynchronously invoked callback) throws an exception, there is no way for that exception to propagate back to the initiator of the asynchronous operation.
    This is a fundamental fact about asynchronous programming: It breaks exception handling.
    The alternative is to meticulously track and propagate errors with callback arguments and return values, but this is tedious and difficult to get right.
    Promises help here by standardizing a way to handle errors and providing a way for errors to propagate correctly through a chain of promises.

Promises are therefore a powerful idiom for asynchronous programming.

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.

Direzione di ricerca

Apri l’articolo sui Promises a cui fa riferimento l’issue e rivedi la sua trattazione esistente della programmazione asincrona. Aggiungi una sezione mirata “Promises vs Callbacks” utilizzando i punti forniti su annidamento, leggibilità e propagazione degli errori, quindi conferma che l’articolo sia coerente con il contenuto circostante.

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

Valutazione

Stack tecnologico
javascript
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.