Skip to content

Commit 700ae3b

Browse files
feat: add Then and Catch methods documentation to Promise class
1 parent f064e90 commit 700ae3b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

doc/promises.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,47 @@ Rejects the Promise object held by the `Napi::Promise::Deferred` object.
7575

7676
* `[in] value`: The Node-API primitive value with which to reject the `Napi::Promise`.
7777

78+
## Promise Methods
79+
80+
### Then
81+
82+
```cpp
83+
<Promise> Napi::Promise::Then(napi_value onFulfilled, napi_value onRejected) const;
84+
```
85+
86+
Attaches fulfillment and/or rejection handlers to the promise and returns a new promise.
87+
88+
**Parameters:**
89+
* `[in] onFulfilled`: A function to be called when the promise is fulfilled
90+
* `[in] onRejected`: A function to be called when the promise is rejected (optional)
91+
92+
**Returns:** A new `<Promise>` that resolves or rejects based on the handler's result.
93+
94+
**Example:**
95+
```cpp
96+
// Single fulfillment handler
97+
Promise newPromise = existingPromise.Then(fulfillmentHandler);
98+
99+
// Both fulfillment and rejection handlers
100+
Promise chainedPromise = existingPromise.Then(onFulfilled, onRejected);
101+
```
102+
103+
### Catch
104+
105+
```cpp
106+
<Promise> Napi::Promise::Catch(napi_value onRejected) const;
107+
```
108+
109+
Attaches a rejection handler to the promise and returns a new promise.
110+
111+
**Parameters:**
112+
* `[in] onRejected`: A function to be called when the promise is rejected
113+
114+
**Returns:** A new `<Promise>` that handles rejection cases.
115+
116+
**Example:**
117+
```cpp
118+
Promise handledPromise = existingPromise.Catch(rejectionHandler);
119+
```
78120

79121
[`Napi::Object`]: ./object.md

0 commit comments

Comments
 (0)