MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / Future

Class Future

include/PyEventLoop.hh:178–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176 * @see https://docs.python.org/3/library/asyncio-future.html#asyncio.Future
177 */
178 struct Future {
179 public:
180 explicit Future(PyObject *future) : _future(future) {};
181 Future(const Future &old) = delete; // forbid copy-initialization
182 Future(Future &&old) : _future(std::exchange(old._future, nullptr)) {}; // clear the moved-from object
183 ~Future() {
184 Py_XDECREF(_future);
185 }
186
187 /**
188 * @brief Mark the Future as done and set its result
189 * @see https://docs.python.org/3/library/asyncio-future.html#asyncio.Future.set_result
190 */
191 void setResult(PyObject *result);
192
193 /**
194 * @brief Mark the Future as done and set an exception
195 * @see https://docs.python.org/3/library/asyncio-future.html#asyncio.Future.set_exception
196 */
197 void setException(PyObject *exception);
198
199 /**
200 * @brief Add a callback to be run when the Future is done
201 * @see https://docs.python.org/3.9/library/asyncio-future.html#asyncio.Future.add_done_callback
202 */
203 void addDoneCallback(PyObject *cb);
204
205 /**
206 * @brief Return True if the Future is cancelled.
207 * @see https://docs.python.org/3.9/library/asyncio-future.html#asyncio.Future.cancelled
208 */
209 bool isCancelled();
210
211 /**
212 * @brief Get the result of the Future.
213 * Would raise exception if the Future is pending, cancelled, or having an exception set.
214 * @see https://docs.python.org/3.9/library/asyncio-future.html#asyncio.Future.result
215 */
216 PyObject *getResult();
217
218 /**
219 * @brief Get the exception object that was set on this Future, or `Py_None` if no exception was set.
220 * Would raise an exception if the Future is pending or cancelled.
221 * @see https://docs.python.org/3.9/library/asyncio-future.html#asyncio.Future.exception
222 */
223 PyObject *getException();
224
225 /**
226 * @brief Get the underlying `asyncio.Future` Python object
227 */
228 inline PyObject *getFutureObject() const {
229 Py_INCREF(_future); // otherwise the object would be GC-ed as this `PyEventLoop::Future` destructs
230 return _future;
231 }
232 protected:
233 PyObject *_future;
234 };
235

Callers 4

createFutureMethod · 0.85
ensureFutureMethod · 0.85
onResolvedCbFunction · 0.85
futureOnDoneCallbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected