mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 08:45:46 +00:00
Bug 1677000 - Add a type alias for MozPromise<T, IOError, true> r=Gijs
To use this type alias, IOUtils::InvokeToIOPromise had to become either a member fn or a friend. Differential Revision: https://phabricator.services.mozilla.com/D99000
This commit is contained in:
parent
3aa75d55bb
commit
c50f24f067
@ -150,8 +150,6 @@ Atomic<bool> IOUtils::sShutdownStarted = Atomic<bool>(false);
|
||||
/* static */
|
||||
template <typename OkT, typename Fn>
|
||||
void IOUtils::RunOnBackgroundThread(Promise* aPromise, Fn aFunc) {
|
||||
using MozPromiseT = MozPromise<OkT, IOError, true>;
|
||||
|
||||
nsCOMPtr<nsISerialEventTarget> bg = GetBackgroundEventTarget();
|
||||
if (!bg) {
|
||||
aPromise->MaybeRejectWithAbortError(
|
||||
@ -159,15 +157,15 @@ void IOUtils::RunOnBackgroundThread(Promise* aPromise, Fn aFunc) {
|
||||
return;
|
||||
}
|
||||
|
||||
InvokeAsync(bg, __func__,
|
||||
[func = std::move(aFunc)]() {
|
||||
Result<OkT, IOError> result = func();
|
||||
if (result.isErr()) {
|
||||
return MozPromiseT::CreateAndReject(result.unwrapErr(),
|
||||
__func__);
|
||||
}
|
||||
return MozPromiseT::CreateAndResolve(result.unwrap(), __func__);
|
||||
})
|
||||
InvokeAsync(
|
||||
bg, __func__,
|
||||
[func = std::move(aFunc)]() {
|
||||
Result<OkT, IOError> result = func();
|
||||
if (result.isErr()) {
|
||||
return IOPromise<OkT>::CreateAndReject(result.unwrapErr(), __func__);
|
||||
}
|
||||
return IOPromise<OkT>::CreateAndResolve(result.unwrap(), __func__);
|
||||
})
|
||||
->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[promise = RefPtr(aPromise)](const OkT& ok) {
|
||||
|
@ -109,6 +109,9 @@ class IOUtils final {
|
||||
private:
|
||||
~IOUtils() = default;
|
||||
|
||||
template <typename T>
|
||||
using IOPromise = MozPromise<T, IOError, true>;
|
||||
|
||||
friend class IOUtilsShutdownBlocker;
|
||||
struct InternalFileInfo;
|
||||
struct InternalWriteAtomicOpts;
|
||||
@ -119,6 +122,10 @@ class IOUtils final {
|
||||
static StaticRefPtr<nsIAsyncShutdownClient> sBarrier;
|
||||
static Atomic<bool> sShutdownStarted;
|
||||
|
||||
template <typename OkT, typename Fn, typename... Args>
|
||||
static RefPtr<IOUtils::IOPromise<OkT>> InvokeToIOPromise(Fn aFunc,
|
||||
Args... aArgs);
|
||||
|
||||
static already_AddRefed<nsIAsyncShutdownClient> GetShutdownBarrier();
|
||||
|
||||
static already_AddRefed<nsISerialEventTarget> GetBackgroundEventTarget();
|
||||
|
Loading…
Reference in New Issue
Block a user