Hi everyone,
I am studying the Outsystems documentation about Defining Asynchronous JavaScript Code with link:
Defining Asynchronous JavaScript Code - OutSystems 11 Documentation
There's a part that confuses me. I'm not sure what to thin of it.
So, in the Call an Asynchronous Client Action part, there's a section wherein the documentation states this:
You can also act upon an unhandled error or a call to "$reject()" occurred in the asynchronous client action. To do that, do one of the following:
It then goes on and gives 2 examples
#Example1
#Example2
So, where my confusion comes in where the documentation says
It talks about the signature "then(onFullfilled, onRejected)" but in the examples above, I do not see any explicit "second" function that caters to the onRejected. I see the catch which I understand, kind of does what is described but what I do not understand is why the documentation talks about "then(onFullfilled, onRejected)", two arguments. But then does not give an example on how it is constructed. Wondering if anyone can give me a sample code snippet on how to construct the "then(onFullfilled, onRejected) " where I can see a function that caters to OnRejected or at least clarify things for me. Thanks!
Hi @Reynald Zackery Saley,
The then() method of Promise instances takes up to two arguments: callback functions for the fulfilled and rejected cases of the Promise. It immediately returns another Promise object, allowing you to chain calls to other promise methods.
OutSystems documentation page talks about non-chaining approach - full signature is "then(onFullfilled, onRejected)". However, the examples showcased there are using Thening/Chaining approach may be for simplified or commonly used examples.
If you need to understand the Promise implementation (chaining & non-chaining), take a look here.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
- Niranjan