Fix timers not being re-sorted on replace
This commit is contained in:
parent
ff72b1f96f
commit
29b16d0856
@ -99,7 +99,6 @@ static PyObject *
|
|||||||
add(Timers *self, PyObject *fargs) {
|
add(Timers *self, PyObject *fargs) {
|
||||||
#define add_doc "add(delay, callback, args) -> Add callback, replacing it if it already exists"
|
#define add_doc "add(delay, callback, args) -> Add callback, replacing it if it already exists"
|
||||||
size_t i;
|
size_t i;
|
||||||
bool added = false;
|
|
||||||
PyObject *callback, *args = NULL;
|
PyObject *callback, *args = NULL;
|
||||||
double delay, at;
|
double delay, at;
|
||||||
if (!PyArg_ParseTuple(fargs, "dO|O", &delay, &callback, &args)) return NULL;
|
if (!PyArg_ParseTuple(fargs, "dO|O", &delay, &callback, &args)) return NULL;
|
||||||
@ -107,18 +106,16 @@ add(Timers *self, PyObject *fargs) {
|
|||||||
|
|
||||||
for (i = 0; i < self->count; i++) {
|
for (i = 0; i < self->count; i++) {
|
||||||
if (self->events[i].callback == callback) {
|
if (self->events[i].callback == callback) {
|
||||||
added = true;
|
|
||||||
self->events[i].at = at;
|
self->events[i].at = at;
|
||||||
Py_CLEAR(self->events[i].args);
|
Py_CLEAR(self->events[i].args);
|
||||||
self->events[i].args = args;
|
self->events[i].args = args;
|
||||||
Py_XINCREF(args);
|
Py_XINCREF(args);
|
||||||
break;
|
qsort(self->events, self->count, sizeof(TimerEvent), compare_events);
|
||||||
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!added) return _add(self, at, callback, args);
|
return _add(self, at, callback, args);
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user