|
1 |
| -#include <array> |
2 |
| -#include "napi.h" |
3 | 1 | #include "../util/util.h"
|
| 2 | +#include "napi.h" |
| 3 | +#include <array> |
4 | 4 |
|
5 | 5 | #if (NAPI_VERSION > 3)
|
6 | 6 |
|
@@ -60,12 +60,12 @@ class TSFNWrap : public base {
|
60 | 60 |
|
61 | 61 | Napi::Value Call(const CallbackInfo &info) {
|
62 | 62 | Napi::Env env = info.Env();
|
63 |
| - DataType *data = new DataType{Napi::Reference<Napi::Value>(Persistent(info[0])), |
64 |
| - Promise::Deferred::New(env)}; |
| 63 | + DataType *data = |
| 64 | + new DataType{Napi::Reference<Napi::Value>(Persistent(info[0])), |
| 65 | + Promise::Deferred::New(env)}; |
65 | 66 | _tsfn.NonBlockingCall(data);
|
66 | 67 | return data->deferred.Promise();
|
67 | 68 | };
|
68 |
| - |
69 | 69 | };
|
70 | 70 |
|
71 | 71 | } // namespace call
|
@@ -145,18 +145,17 @@ using ContextType = std::nullptr_t;
|
145 | 145 | // Data passed (as pointer) to [Non]BlockingCall
|
146 | 146 | struct DataType {
|
147 | 147 | Promise::Deferred deferred;
|
148 |
| - bool reject; |
149 | 148 | };
|
150 | 149 |
|
151 | 150 | // CallJs callback function
|
152 |
| -static void CallJs(Napi::Env env, Function jsCallback, ContextType * /*context*/, |
153 |
| - DataType *data) { |
| 151 | +static void CallJs(Napi::Env env, Function jsCallback, |
| 152 | + ContextType * /*context*/, DataType *data) { |
154 | 153 | if (env != nullptr) {
|
155 | 154 | if (data != nullptr) {
|
156 |
| - if (data->reject) { |
157 |
| - data->deferred.Reject(env.Undefined()); |
| 155 | + if (jsCallback.IsEmpty()) { |
| 156 | + data->deferred.Resolve(Boolean::New(env, true)); |
158 | 157 | } else {
|
159 |
| - data->deferred.Resolve(env.Undefined()); |
| 158 | + data->deferred.Reject(String::New(env, "jsCallback is not empty")); |
160 | 159 | }
|
161 | 160 | }
|
162 | 161 | }
|
@@ -193,14 +192,7 @@ class TSFNWrap : public base {
|
193 | 192 | }
|
194 | 193 |
|
195 | 194 | Napi::Value Call(const CallbackInfo &info) {
|
196 |
| - if (info.Length() == 0 || !info[0].IsBoolean()) { |
197 |
| - NAPI_THROW( |
198 |
| - Napi::TypeError::New(info.Env(), "Expected argument 0 to be boolean"), |
199 |
| - Value()); |
200 |
| - } |
201 |
| - |
202 |
| - auto *data = |
203 |
| - new DataType{Promise::Deferred::New(info.Env()), info[0].ToBoolean()}; |
| 195 | + auto data = new DataType{Promise::Deferred::New(info.Env())}; |
204 | 196 | _tsfn.NonBlockingCall(data);
|
205 | 197 | return data->deferred.Promise();
|
206 | 198 | };
|
@@ -323,8 +315,8 @@ namespace simple {
|
323 | 315 |
|
324 | 316 | using ContextType = std::nullptr_t;
|
325 | 317 |
|
326 |
| -// Full type of our ThreadSafeFunctionEx. We don't specify the `ContextType` here |
327 |
| -// (even though the _default_ for the type argument is `std::nullptr_t`) to |
| 318 | +// Full type of our ThreadSafeFunctionEx. We don't specify the `ContextType` |
| 319 | +// here (even though the _default_ for the type argument is `std::nullptr_t`) to |
328 | 320 | // demonstrate construction with no type arguments.
|
329 | 321 | using TSFN = ThreadSafeFunctionEx<>;
|
330 | 322 |
|
|
0 commit comments