Index: src/OFTimer.h ================================================================== --- src/OFTimer.h +++ src/OFTimer.h @@ -19,10 +19,11 @@ #ifdef OF_HAVE_BLOCKS typedef void (^of_timer_block_t)(void); #endif @class OFDate; +@class OFCondition; /** * \brief A class for creating and firing timers. */ @interface OFTimer: OFObject @@ -35,10 +36,11 @@ BOOL repeats; #ifdef OF_HAVE_BLOCKS of_timer_block_t block; #endif BOOL isValid; + OFCondition *condition; } /** * \brief Creates and schedules a new timer with the specified time interval. * @@ -282,6 +284,11 @@ * * \return The time interval in which the timer will repeat, if it is a * repeating timer */ - (double)timeInterval; + +/** + * \brief Waits until the timer fired. + */ +- (void)waitUntilDone; @end Index: src/OFTimer.m ================================================================== --- src/OFTimer.m +++ src/OFTimer.m @@ -17,12 +17,14 @@ #include "config.h" #import "OFTimer.h" #import "OFDate.h" #import "OFRunLoop.h" +#import "OFThread.h" #import "OFInvalidArgumentException.h" +#import "OFNotImplementedException.h" #import "autorelease.h" #import "macros.h" @implementation OFTimer @@ -195,10 +197,18 @@ objc_autoreleasePoolPop(pool); return [timer autorelease]; } #endif + +- init +{ + Class c = [self class]; + [self release]; + @throw [OFNotImplementedException exceptionWithClass: c + selector: _cmd]; +} - OF_initWithFireDate: (OFDate*)fireDate_ interval: (double)interval_ target: (id)target_ selector: (SEL)selector_ @@ -217,10 +227,11 @@ object1 = [object1_ retain]; object2 = [object2_ retain]; arguments = arguments_; repeats = repeats_; isValid = YES; + condition = [[OFCondition alloc] init]; } @catch (id e) { [self release]; @throw e; } @@ -307,10 +318,11 @@ [object1 release]; [object2 release]; #ifdef OF_HAVE_BLOCKS [block release]; #endif + [condition release]; [super dealloc]; } - (of_comparison_result_t)compare: (id )object_ @@ -352,10 +364,14 @@ } #ifdef OF_HAVE_BLOCKS } #endif + [condition lock]; + [condition signal]; + [condition unlock]; + if (repeats) { OFDate *old = fireDate; fireDate = [[OFDate alloc] initWithTimeIntervalSinceNow: interval]; [old release]; @@ -382,6 +398,13 @@ - (BOOL)isValid { return isValid; } + +- (void)waitUntilDone +{ + [condition lock]; + [condition wait]; + [condition unlock]; +} @end