1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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 
7 #ifndef XPCOM_THREADS_NSIDISCARDABLERUNNABLE_H_
8 #define XPCOM_THREADS_NSIDISCARDABLERUNNABLE_H_
9 
10 #include "nsISupports.h"
11 
12 /**
13  * An interface implemented by nsIRunnable tasks for which nsIRunnable::Run()
14  * might not be called.
15  */
16 #define NS_IDISCARDABLERUNNABLE_IID                  \
17   {                                                  \
18     0xde93dc4c, 0x755c, 0x4cdc, {                    \
19       0x96, 0x76, 0x35, 0xc6, 0x48, 0x81, 0x59, 0x78 \
20     }                                                \
21   }
22 
23 class NS_NO_VTABLE nsIDiscardableRunnable : public nsISupports {
24  public:
25   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDISCARDABLERUNNABLE_IID)
26 
27   /**
28    * Called exactly once on a queued task only if nsIRunnable::Run() is not
29    * called.
30    */
31   virtual void OnDiscard() = 0;
32 
33  protected:
34   nsIDiscardableRunnable() = default;
35   virtual ~nsIDiscardableRunnable() = default;
36 };
37 
38 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDiscardableRunnable,
39                               NS_IDISCARDABLERUNNABLE_IID)
40 
41 #endif  // XPCOM_THREADS_NSIDISCARDABLERUNNABLE_H_
42