61class EXPCL_PANDA_EVENT
AsyncFuture :
public TypedReferenceCount {
66 EXTENSION(
static PyObject *__await__(PyObject *self));
67 EXTENSION(
static PyObject *__iter__(PyObject *self));
69 INLINE
bool done()
const;
71 EXTENSION(PyObject *result(PyObject *timeout = Py_None)
const);
79 EXTENSION(PyObject *add_done_callback(PyObject *self, PyObject *fn));
81 EXTENSION(
static PyObject *
gather(PyObject *args));
83 virtual void output(std::ostream &out)
const;
86 BLOCKING
void wait(
double timeout);
93 INLINE
void set_result(TypedReferenceCount *result);
96 void set_result(TypedObject *ptr, ReferenceCount *ref_ptr);
99 INLINE
void get_result(TypedObject *&ptr, ReferenceCount *&ref_ptr)
const;
104 virtual bool is_task()
const {
return false;}
106 void notify_done(
bool clean_exit);
122 INLINE
bool try_lock_pending();
123 INLINE
void unlock(FutureState new_state = FS_pending);
124 INLINE
bool set_future_state(FutureState state);
126 AsyncTaskManager *_manager;
127 TypedObject *_result;
128 PT(ReferenceCount) _result_ref;
129 AtomicAdjust::Integer _future_state;
131 std::string _done_event;
136 friend class AsyncGatheringFuture;
137 friend class AsyncTaskChain;
138 friend class PythonTask;
141 static TypeHandle get_class_type() {
144 static void init_type() {
145 TypedReferenceCount::init_type();
147 TypedReferenceCount::get_class_type());
149 virtual TypeHandle get_type()
const {
150 return get_class_type();
152 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
155 static TypeHandle _type_handle;
158INLINE std::ostream &operator << (std::ostream &out,
const AsyncFuture &fut) {
166class EXPCL_PANDA_EVENT AsyncGatheringFuture final :
public AsyncFuture {
168 AsyncGatheringFuture(AsyncFuture::Futures futures);
171 virtual bool cancel()
override;
174 INLINE AsyncFuture *
get_future(
size_t i)
const;
175 INLINE TypedObject *
get_result(
size_t i)
const;
178 const Futures _futures;
179 AtomicAdjust::Integer _num_pending;
181 friend class AsyncFuture;
187 static void init_type() {
188 AsyncFuture::init_type();
190 AsyncFuture::get_class_type());
192 virtual TypeHandle get_type()
const override {
193 return get_class_type();
195 virtual TypeHandle force_init_type()
override {init_type();
return get_class_type();}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class represents a thread-safe handle to a promised future result of an asynchronous operation,...
virtual bool cancel()
Cancels the future.
bool cancelled() const
Returns true if the future was cancelled.
void set_result(std::nullptr_t)
Sets this future's result.
void wait()
Waits until the future is done.
set_done_event
Sets the event name that will be triggered when the future finishes.
AsyncFuture()
Initializes the future in the pending state.
get_done_event
Returns the event name that will be triggered when the future finishes.
TypedObject * get_result() const
Returns this future's result.
static AsyncFuture * gather(Futures futures)
Creates a new future that returns `done()` when all of the contained futures are done.
bool done() const
Returns true if the future is done or has been cancelled.
TypedObject * get_result(size_t i) const
Returns the result of the nth future that was passed into the constructor.
size_t get_num_futures() const
Returns the number of futures that were passed to the constructor.
AsyncFuture * get_future(size_t i) const
Returns the nth future that was passed into the constructor.
virtual bool cancel() override
Cancels all the futures.
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
This class represents a concrete task performed by an AsyncManager.
This class implements a condition variable; see ConditionVar for a brief introduction to this class.
An optional parameter associated with an event.
TypeHandle is the identifier used to differentiate C++ class types.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.