1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef _mozilla_dom_ClientDOMUtil_h
7 #define _mozilla_dom_ClientDOMUtil_h
9 #include "mozilla/dom/ClientIPCTypes.h"
10 #include "mozilla/dom/ClientOpPromise.h"
11 #include "mozilla/dom/DOMMozPromiseRequestHolder.h"
12 #include "mozilla/dom/WorkerPrivate.h"
14 class nsIGlobalObject
;
16 namespace mozilla::dom
{
18 // Utility method to properly execute a ClientManager operation. It
19 // will properly hold a worker thread alive and avoid executing callbacks
20 // if the thread is shutting down.
21 template <typename Func
, typename Arg
, typename Resolve
, typename Reject
>
22 void StartClientManagerOp(Func aFunc
, const Arg
& aArg
, nsIGlobalObject
* aGlobal
,
23 Resolve aResolve
, Reject aReject
) {
24 MOZ_DIAGNOSTIC_ASSERT(aGlobal
);
26 nsCOMPtr
<nsISerialEventTarget
> target
= aGlobal
->SerialEventTarget();
28 MakeRefPtr
<DOMMozPromiseRequestHolder
<ClientOpPromise
>>(aGlobal
);
33 [aResolve
, holder
](const ClientOpResult
& aResult
) {
37 [aReject
, holder
](const CopyableErrorResult
& aResult
) {
44 } // namespace mozilla::dom
46 #endif // _mozilla_dom_ClientDOMUtil_h