1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
7 #include
"nsIRunnable.idl"
10 #include
"mozilla/AlreadyAddRefed.h"
13 native alreadyAddRefed_nsIRunnable
(already_AddRefed
<nsIRunnable
>);
16 * The primary use of this interface is to allow any nsISerialEventTarget to
17 * provide Direct Task dispatching which is similar (but not identical to) the
18 * microtask semantics of JS promises.
19 * New direct task may be dispatched when a current direct task is running. In
20 * which case they will be run in FIFO order.
22 [uuid(e05bf0fe
-94b7
-4e28
-8462-a8368da9c136
)]
23 interface nsIDirectTaskDispatcher
: nsISupports
26 * Dispatch an event for the nsISerialEventTarget, using the direct task
29 * This function must be called from the same nsISerialEventTarget
30 * implementing direct task dispatching.
33 * The alreadyAddRefed<> event to dispatch.
36 [noscript
] void dispatchDirectTask
(in alreadyAddRefed_nsIRunnable event
);
39 * Synchronously run any pending direct tasks queued.
41 [noscript
] void drainDirectTasks
();
44 * Returns true if any direct tasks are pending.
46 [noscript
] bool haveDirectTasks
();
49 // Infallible version of the above. Will assert that it is successful.
50 bool HaveDirectTasks
() {
52 MOZ_ALWAYS_SUCCEEDS
(HaveDirectTasks
(&value
));