* @brief Wrapper to remove the reference of the timer after the job finishes */
| 39 | * @brief Wrapper to remove the reference of the timer after the job finishes |
| 40 | */ |
| 41 | static PyObject *timerJobWrapper(PyObject *jobFn, PyObject *args) { |
| 42 | PyObject *_loop = PyTuple_GetItem(args, 0); |
| 43 | PyEventLoop::AsyncHandle::id_t handleId = PyLong_AsLong(PyTuple_GetItem(args, 1)); |
| 44 | double delaySeconds = PyFloat_AsDouble(PyTuple_GetItem(args, 2)); |
| 45 | bool repeat = (bool)PyLong_AsLong(PyTuple_GetItem(args, 3)); |
| 46 | |
| 47 | PyObject *ret = PyObject_CallObject(jobFn, NULL); // jobFn() |
| 48 | Py_XDECREF(ret); // don't care about its return value |
| 49 | |
| 50 | PyObject *errType, *errValue, *traceback; // we can't call any Python code unless the error indicator is clear |
| 51 | PyErr_Fetch(&errType, &errValue, &traceback); |
| 52 | // Making sure a `AsyncHandle::fromId` call is close to its `handle`'s use. |
| 53 | // We need to ensure the memory block doesn't move for reallocation before we can use the pointer, |
| 54 | // as we could have multiple new `setTimeout` calls to expand the `_timeoutIdMap` vector while running the job function in parallel. |
| 55 | auto handle = PyEventLoop::AsyncHandle::fromId(handleId); |
| 56 | if (repeat && !handle->cancelled()) { |
| 57 | _enqueueWithDelay(_loop, handleId, jobFn, delaySeconds, repeat); |
| 58 | } else { |
| 59 | handle->removeRef(); |
| 60 | } |
| 61 | |
| 62 | if (errType != NULL) { // PyErr_Occurred() |
| 63 | PyErr_Restore(errType, errValue, traceback); |
| 64 | return NULL; |
| 65 | } else { |
| 66 | Py_RETURN_NONE; |
| 67 | } |
| 68 | } |
| 69 | static PyMethodDef timerJobWrapperDef = {"timerJobWrapper", timerJobWrapper, METH_VARARGS, NULL}; |
| 70 | |
| 71 | PyEventLoop::AsyncHandle PyEventLoop::enqueue(PyObject *jobFn) { |
nothing calls this directly
no test coverage detected