How can you retry after an exception in Javascript when using promises?

前端 未结 3 1164
温柔的废话
温柔的废话 2021-01-12 08:03

I\'m using the Bluebird promise library. I have a chain of promisified functions like the following:

    receiveMessageAsync(params)
    .then(function(data)         


        
3条回答
  •  无人共我
    2021-01-12 08:24

    I just released https://github.com/zyklus/promise-repeat, which retries a promise until it either times out or a maximum number of attempts are hit. It allows you to write:

    receiveMessageAsync(params)
    ...
    .spread(retry(
        function(response, data) {
            return sendResponseAsync(response);
        }
    ))
    ...
    

提交回复
热议问题