Skip to content

Commit 5f3f37d

Browse files
doc: update Then and Catch method signatures
1 parent b594d54 commit 5f3f37d

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

doc/promises.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,42 +80,51 @@ Rejects the Promise object held by the `Napi::Promise::Deferred` object.
8080
### Then
8181

8282
```cpp
83-
<Promise> Napi::Promise::Then(napi_value onFulfilled, napi_value onRejected) const;
83+
Napi::Promise Napi::Promise::Then(napi_value onFulfilled) const;
84+
Napi::Promise Napi::Promise::Then(const Function& onFulfilled) const;
8485
```
8586
86-
Attaches fulfillment and/or rejection handlers to the promise and returns a new promise.
87+
Attaches fulfillment handler to the promise and returns a new promise.
8788
8889
**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)
90+
* `[in] onFulfilled`: The fulfillment handler for the promise. May be any of:
91+
- `napi_value` – a JavaScript function to be called when the promise is fulfilled.
92+
- `const Function&` – the [`Napi::Function`](function.md) to be called when the promise is fulfilled.
9193
92-
**Returns:** A new `<Promise>` that resolves or rejects based on the handler's result.
94+
**Returns:** A new `Napi::Promise` that resolves or rejects based on the handler's result.
9395
94-
**Example:**
95-
```cpp
96-
// Single fulfillment handler
97-
Promise newPromise = existingPromise.Then(fulfillmentHandler);
96+
### Then
9897
99-
// Both fulfillment and rejection handlers
100-
Promise chainedPromise = existingPromise.Then(onFulfilled, onRejected);
98+
```cpp
99+
Napi::Promise Napi::Promise::Then(napi_value onFulfilled, napi_value onRejected) const;
100+
Napi::Promise Napi::Promise::Then(const Function& onFulfilled,
101+
const Function& onRejected) const;
101102
```
102103

103-
### Catch
104+
Attaches fulfillment and/or rejection handlers to the promise and returns a new promise.
104105

106+
**Parameters:**
107+
* `[in] onFulfilled`: The fulfillment handler for the promise. May be any of:
108+
- `napi_value` – a JavaScript function to be called when the promise is fulfilled.
109+
- `const Function&` – the [`Napi::Function`](function.md) to be called when the promise is fulfilled.
110+
* `[in] onRejected` (optional): The rejection handler for the promise. May be any of:
111+
- `napi_value` – a JavaScript function to be called when the promise is rejected.
112+
- `const Function&` – the [`Napi::Function`](function.md) to be called when the promise is rejected.
113+
114+
### Catch
105115
```cpp
106-
<Promise> Napi::Promise::Catch(napi_value onRejected) const;
116+
Napi::Promise Napi::Promise::Catch(napi_value onRejected) const;
117+
Napi::Promise Napi::Promise::Catch(const Function& onRejected) const;
107118
```
108119
109120
Attaches a rejection handler to the promise and returns a new promise.
110121
111122
**Parameters:**
112-
* `[in] onRejected`: A function to be called when the promise is rejected
123+
* `[in] onRejected`: The rejection handler for the promise. May be any of:
124+
- `napi_value` – a JavaScript function to be called when the promise is rejected.
125+
- `const Function&` – the [`Napi::Function`](function.md) to be called when the promise is rejected.
113126
114-
**Returns:** A new `<Promise>` that handles rejection cases.
115-
116-
**Example:**
117-
```cpp
118-
Promise handledPromise = existingPromise.Catch(rejectionHandler);
119-
```
127+
**Returns:** A new `Napi::Promise` that handles rejection cases.
120128
121129
[`Napi::Object`]: ./object.md
130+
[`Napi::Function`]: ./function.md)

0 commit comments

Comments
 (0)