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

Suggestion for Additions to Article on Promise

Aberta
#2,807 0 comentários 2 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
HTML
Estrelas
25.5k
Forks
4k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Abra o artigo sobre Promises referenciado pela issue e revise a discussão existente sobre programação assíncrona. Adicione uma seção focada em “Promises vs Callbacks” usando os pontos fornecidos sobre aninhamento, legibilidade e propagação de erros e, em seguida, confirme que o artigo está consistente com o conteúdo ao redor.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.