chore: clean up promise resoution with helpers (#17268)
This commit is contained in:
parent
3e5a98b5f4
commit
d9234798d3
6 changed files with 26 additions and 52 deletions
|
@ -65,11 +65,6 @@ scoped_refptr<TracingController::TraceDataEndpoint> GetTraceDataEndpoint(
|
|||
result_file_path, base::Bind(callback, result_file_path));
|
||||
}
|
||||
|
||||
void OnRecordingStopped(const atom::util::CopyablePromise& promise,
|
||||
const base::FilePath& path) {
|
||||
promise.GetPromise().Resolve(path);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
|
||||
const base::FilePath& path) {
|
||||
atom::util::Promise promise(isolate);
|
||||
|
@ -78,28 +73,22 @@ v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
|
|||
// TODO(zcbenz): Remove the use of CopyablePromise when the
|
||||
// CreateFileEndpoint API accepts OnceCallback.
|
||||
TracingController::GetInstance()->StopTracing(GetTraceDataEndpoint(
|
||||
path,
|
||||
base::Bind(&OnRecordingStopped, atom::util::CopyablePromise(promise))));
|
||||
path, base::Bind(atom::util::CopyablePromise::ResolveCopyablePromise<
|
||||
const base::FilePath&>,
|
||||
atom::util::CopyablePromise(promise))));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void OnCategoriesAvailable(atom::util::Promise promise,
|
||||
const std::set<std::string>& categories) {
|
||||
promise.Resolve(categories);
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
|
||||
atom::util::Promise promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
// Note: This method always succeeds.
|
||||
TracingController::GetInstance()->GetCategories(
|
||||
base::BindOnce(&OnCategoriesAvailable, std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
TracingController::GetInstance()->GetCategories(base::BindOnce(
|
||||
atom::util::Promise::ResolvePromise<const std::set<std::string>&>,
|
||||
std::move(promise)));
|
||||
|
||||
void OnTracingStarted(atom::util::Promise promise) {
|
||||
promise.Resolve();
|
||||
return handle;
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> StartTracing(
|
||||
|
@ -110,7 +99,8 @@ v8::Local<v8::Promise> StartTracing(
|
|||
|
||||
// Note: This method always succeeds.
|
||||
TracingController::GetInstance()->StartTracing(
|
||||
trace_config, base::BindOnce(&OnTracingStarted, std::move(promise)));
|
||||
trace_config, base::BindOnce(atom::util::Promise::ResolveEmptyPromise,
|
||||
std::move(promise)));
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue