diff --git a/src/ae.c b/src/ae.c index ecbaa94f..742388d8 100644 --- a/src/ae.c +++ b/src/ae.c @@ -344,6 +344,7 @@ static int processTimeEvents(aeEventLoop *eventLoop) { * if flags has AE_FILE_EVENTS set, file events are processed. * if flags has AE_TIME_EVENTS set, time events are processed. * if flags has AE_DONT_WAIT set the function returns ASAP until all + * if flags has AE_CALL_AFTER_SLEEP set, the aftersleep callback is called. * the events that's possible to process without to wait are processed. * * The function returns the number of events processed. */ @@ -403,7 +404,7 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags) numevents = aeApiPoll(eventLoop, tvp); /* After sleep callback. */ - if (eventLoop->aftersleep != NULL) + if (eventLoop->aftersleep != NULL && flags & AE_CALL_AFTER_SLEEP) eventLoop->aftersleep(eventLoop); for (j = 0; j < numevents; j++) { @@ -460,7 +461,7 @@ void aeMain(aeEventLoop *eventLoop) { while (!eventLoop->stop) { if (eventLoop->beforesleep != NULL) eventLoop->beforesleep(eventLoop); - aeProcessEvents(eventLoop, AE_ALL_EVENTS); + aeProcessEvents(eventLoop, AE_ALL_EVENTS|AE_CALL_AFTER_SLEEP); } } diff --git a/src/ae.h b/src/ae.h index e3617759..c49bfe23 100644 --- a/src/ae.h +++ b/src/ae.h @@ -46,6 +46,7 @@ #define AE_TIME_EVENTS 2 #define AE_ALL_EVENTS (AE_FILE_EVENTS|AE_TIME_EVENTS) #define AE_DONT_WAIT 4 +#define AE_CALL_AFTER_SLEEP 8 #define AE_NOMORE -1 #define AE_DELETED_EVENT_ID -1