@@ -80,42 +80,51 @@ Rejects the Promise object held by the `Napi::Promise::Deferred` object.
80
80
### Then
81
81
82
82
``` 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;
84
85
```
85
86
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.
87
88
88
89
**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.
91
93
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.
93
95
94
- **Example:**
95
- ```cpp
96
- // Single fulfillment handler
97
- Promise newPromise = existingPromise.Then(fulfillmentHandler);
96
+ ### Then
98
97
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;
101
102
```
102
103
103
- ### Catch
104
+ Attaches fulfillment and/or rejection handlers to the promise and returns a new promise.
104
105
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
105
115
``` 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;
107
118
```
108
119
109
120
Attaches a rejection handler to the promise and returns a new promise.
110
121
111
122
**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.
113
126
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.
120
128
121
129
[`Napi::Object`]: ./object.md
130
+ [`Napi::Function`]: ./function.md)
0 commit comments