!986 [Bug]: getTask 的任务没有 on remove 回调

Merge pull request !986 from ZhangJianxin/on_remove
This commit is contained in:
openharmony_ci 2024-09-21 14:17:51 +00:00 committed by Gitee
commit d76035330c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 8 additions and 1 deletions

View File

@ -123,6 +123,7 @@ private:
static void UvUnrefTaskContext(uv_work_t *work, int status);
static void RegisterForegroundResume();
static void AddTask(std::shared_ptr<ContextInfo> context);
static void AddRemoveListener(const std::shared_ptr<ContextInfo> &context);
bool Equals(napi_env env, napi_value value, napi_ref copy);
static std::mutex createMutex_;

View File

@ -202,6 +202,12 @@ int32_t JsTask::CreateExec(const std::shared_ptr<ContextInfo> &context, int32_t
REQUEST_HILOGE("End create task in JsTask CreateExec, seq: %{public}d, failed: %{public}d", seq, ret);
return ret;
}
JsTask::AddRemoveListener(context);
return ret;
}
void JsTask::AddRemoveListener(const std::shared_ptr<ContextInfo> &context)
{
std::string tid = context->tid;
context->task->listenerMutex_.lock();
context->task->notifyDataListenerMap_[SubscribeType::REMOVE] =
@ -209,7 +215,6 @@ int32_t JsTask::CreateExec(const std::shared_ptr<ContextInfo> &context, int32_t
context->task->listenerMutex_.unlock();
RequestManager::GetInstance()->AddListener(
tid, SubscribeType::REMOVE, context->task->notifyDataListenerMap_[SubscribeType::REMOVE]);
return ret;
}
napi_value JsTask::GetCtor(napi_env env, Version version)
@ -424,6 +429,7 @@ bool JsTask::GetTaskOutput(std::shared_ptr<ContextInfo> context)
std::lock_guard<std::mutex> lockGuardContext(JsTask::taskContextMutex_);
JsTask::AddTaskContextMap(tid, context);
}
JsTask::AddRemoveListener(context);
return true;
}