Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -35,10 +35,11 @@ #ifdef OF_HAVE_THREADS OFMutex *timersQueueLock; #endif OFStreamObserver *streamObserver; OFMutableDictionary *readQueues; + BOOL running; } /*! * @brief Returns the main run loop. * @@ -99,6 +100,12 @@ /*! * @brief Starts the run loop. */ - (void)run; + +/*! + * @brief Stops the run loop. If there is still an operation being executed, it + * is finished before the run loop stops. + */ +- (void)stop; @end Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -583,11 +583,13 @@ OF_ENSURE(0); } - (void)run { - for (;;) { + running = YES; + + while (running) { void *pool = objc_autoreleasePoolPush(); OFDate *now = [OFDate date]; OFTimer *timer; OFDate *nextTimer; @@ -645,6 +647,12 @@ } objc_autoreleasePoolPop(pool); } } + +- (void)stop +{ + running = NO; + [streamObserver cancel]; +} @end