| 200 | } |
| 201 | |
| 202 | static Value TestAcquire(const CallbackInfo& info) { |
| 203 | Function cb = info[0].As<Function>(); |
| 204 | Napi::Env env = info.Env(); |
| 205 | |
| 206 | // We pass the test data to the Finalizer for cleanup. The finalizer is |
| 207 | // responsible for deleting this data as well. |
| 208 | TestData* testData = new TestData(Promise::Deferred::New(info.Env())); |
| 209 | |
| 210 | testData->tsfn = |
| 211 | ThreadSafeFunction::New(env, |
| 212 | cb, |
| 213 | "Test", |
| 214 | 0, |
| 215 | 1, |
| 216 | testData, |
| 217 | std::function<decltype(AcquireFinalizerCallback)>( |
| 218 | AcquireFinalizerCallback), |
| 219 | testData); |
| 220 | |
| 221 | Object result = Object::New(env); |
| 222 | result["createThread"] = |
| 223 | Function::New(env, CreateThread, "createThread", testData); |
| 224 | result["stopThreads"] = |
| 225 | Function::New(env, StopThreads, "stopThreads", testData); |
| 226 | result["promise"] = testData->deferred.Promise(); |
| 227 | |
| 228 | return result; |
| 229 | } |
| 230 | } // namespace |
| 231 | |
| 232 | Object InitThreadSafeFunctionSum(Env env) { |