Index: src/OFThreadPool.m ================================================================== --- src/OFThreadPool.m +++ src/OFThreadPool.m @@ -31,16 +31,10 @@ #ifdef OF_HAVE_BLOCKS of_thread_pool_block_t _block; #endif } -+ (instancetype)jobWithTarget: (id)target - selector: (SEL)selector - object: (id)object; -#ifdef OF_HAVE_BLOCKS -+ (instancetype)jobWithBlock: (of_thread_pool_block_t)block; -#endif - initWithTarget: (id)target selector: (SEL)selector object: (id)object; #ifdef OF_HAVE_BLOCKS - initWithBlock: (of_thread_pool_block_t)block; @@ -47,26 +41,10 @@ #endif - (void)perform; @end @implementation OFThreadPoolJob -+ (instancetype)jobWithTarget: (id)target - selector: (SEL)selector - object: (id)object -{ - return [[[self alloc] initWithTarget: target - selector: selector - object: object] autorelease]; -} - -#ifdef OF_HAVE_BLOCKS -+ (instancetype)jobWithBlock: (of_thread_pool_block_t)block -{ - return [[[self alloc] initWithBlock: block] autorelease]; -} -#endif - - initWithTarget: (id)target selector: (SEL)selector object: (id)object { self = [super init]; @@ -348,22 +326,32 @@ - (void)dispatchWithTarget: (id)target selector: (SEL)selector object: (id)object { - [self of_dispatchJob: [OFThreadPoolJob jobWithTarget: target - selector: selector - object: object]]; + OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithTarget: target + selector: selector + object: object]; + @try { + [self of_dispatchJob: job]; + } @finally { + [job release]; + } } #ifdef OF_HAVE_BLOCKS - (void)dispatchWithBlock: (of_thread_pool_block_t)block { - [self of_dispatchJob: [OFThreadPoolJob jobWithBlock: block]]; + OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithBlock: block]; + @try { + [self of_dispatchJob: job]; + } @finally { + [job release]; + } } #endif - (size_t)size { return _size; } @end