- ECMAScript Cookbook
- Ross Harrison
- 103字
- 2021-08-27 19:27:43
Simulating finally with the promise API
In a previous recipe, we saw how catch can be used to handle errors, whether a promise has rejected, or a callback has thrown an error. Sometimes, it is desirable to execute code whether or not an error state has been detected. In the context of try/catch blocks, the finally block can be used for this purpose. We have to do a little more work to get the same behavior when working with promises
In this recipe, we'll see how a final then call to execute some code in both successful and failing fulfillment states.