1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JS_CONCURRENT_MODULE_TASKPOOL_TASK_H_ 17 #define JS_CONCURRENT_MODULE_TASKPOOL_TASK_H_ 18 19 #include <mutex> 20 #include <queue> 21 #include <uv.h> 22 23 #include "napi/native_api.h" 24 25 namespace Commonlibrary::Concurrent::TaskPoolModule { 26 enum TaskState { NOT_FOUND, WAITING, RUNNING, TERMINATED, CANCELED }; 27 28 class Task { 29 public: 30 Task() = default; 31 ~Task() = default; 32 33 static napi_value TaskConstructor(napi_env env, napi_callback_info cbinfo); 34 35 napi_ref objRef_; 36 uint32_t executeId_ = 0; 37 uint32_t taskId_ = 0; 38 }; 39 40 struct TaskInfo { 41 napi_env env = nullptr; 42 napi_deferred deferred = nullptr; 43 napi_value promise = nullptr; 44 napi_value result = nullptr; 45 napi_value serializationData = nullptr; 46 uv_async_t *onResultSignal = nullptr; 47 uint32_t taskId; 48 uint32_t executeId; 49 bool success = true; 50 void *worker = nullptr; 51 }; 52 } // namespace Commonlibrary::Concurrent::TaskPoolModule 53 #endif // JS_CONCURRENT_MODULE_TASKPOOL_TASK_H_