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

Suggestion for Additions to Article on Promise

Ouverte
#2,807 0 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
HTML
Étoiles
25.5k
Forks
4k
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Ouvrez l’article sur les Promises référencé par l’issue et examinez sa présentation actuelle de la programmation asynchrone. Ajoutez une section ciblée « Promises vs Callbacks » en utilisant les points fournis sur l’imbrication, la lisibilité et la propagation des erreurs, puis confirmez que l’article reste cohérent avec le contenu environnant.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript
Domaine
documentation
Type d'issue
Documentation
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.