chore: add Then helper for native promises (#16978)
This commit is contained in:
parent
a04d9ef35b
commit
ef2e7d95fe
1 changed files with 12 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/common/api/locker.h"
|
#include "atom/common/api/locker.h"
|
||||||
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
|
|
||||||
|
@ -46,6 +47,17 @@ class Promise : public base::RefCounted<Promise> {
|
||||||
return GetInner()->Reject(GetContext(), v8::Undefined(isolate()));
|
return GetInner()->Reject(GetContext(), v8::Undefined(isolate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::MaybeLocal<v8::Promise> Then(base::Closure cb) {
|
||||||
|
v8::HandleScope handle_scope(isolate());
|
||||||
|
v8::Context::Scope context_scope(
|
||||||
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
||||||
|
v8::Local<v8::Value> value = mate::ConvertToV8(isolate(), cb);
|
||||||
|
v8::Local<v8::Function> handler = v8::Local<v8::Function>::Cast(value);
|
||||||
|
|
||||||
|
return GetHandle()->Then(GetContext(), handler);
|
||||||
|
}
|
||||||
|
|
||||||
// Promise resolution is a microtask
|
// Promise resolution is a microtask
|
||||||
// We use the MicrotasksRunner to trigger the running of pending microtasks
|
// We use the MicrotasksRunner to trigger the running of pending microtasks
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue