43 _operations = [[CPArray alloc] init];
48 selector:@selector(_runNextOpsInQueue)
55 - (void)_runNextOpsInQueue
57 if (!_suspended && [
self operationCount] > 0)
60 count = [_operations count];
62 for (; i < count; i++)
64 var op = [_operations objectAtIndex:i];
65 if ([op isReady] && ![op isFinished] && ![op isExecuting])
73 - (void)_enableTimer:(BOOL)enable
89 selector:@selector(_runNextOpsInQueue)
104 [_operations addObject:anOperation];
105 [
self _sortOpsByPriority:_operations];
115 - (void)addOperations:(CPArray)ops waitUntilFinished:(BOOL)wait
121 [
self _sortOpsByPriority:ops];
122 [
self _runOpsSynchronously:ops];
125 [_operations addObjectsFromArray:ops];
126 [
self _sortOpsByPriority:_operations];
134 - (void)addOperationWithFunction:(JSObject)aFunction
139 - (CPArray)operations
144 - (int)operationCount
148 return [_operations count];
157 - (void)cancelAllOperations
162 count = [_operations count];
164 for (; i < count; i++)
166 [[_operations objectAtIndex:i] cancel];
174 - (void)waitUntilAllOperationsAreFinished
177 [
self _enableTimer:NO];
178 [
self _runOpsSynchronously:_operations];
181 [
self _enableTimer:YES];
190 - (int)maxConcurrentOperationCount
199 - (void)setSuspended:(BOOL)suspend
201 _suspended = suspend;
202 [
self _enableTimer:!suspend];
213 - (void)_sortOpsByPriority:(CPArray)someOps
217 [someOps sortUsingFunction:function(lhs, rhs)
219 if ([lhs queuePriority] < [rhs queuePriority])
225 if ([lhs queuePriority] > [rhs queuePriority])
239 - (void)_runOpsSynchronously:(CPArray)ops
252 for (; i < count; i++)
254 var op = [ops objectAtIndex:i];
255 if ([op isReady] && ![op isFinished] && ![op isExecuting])
262 for (i = 0; i < count; i++)
264 var op = [ops objectAtIndex:i];
265 if (![op isFinished] && ![op isCancelled])
282 [cpOperationMainQueue setName:@"main"];
void willChangeValueForKey:(CPString aKey)
An immutable string (collection of characters).
Represents an operation using a JavaScript function that can be run in an CPOperationQueue.
void addOperation:(CPOperation anOperation)
CPOperationQueue mainQueue()
void didChangeValueForKey:(CPString aKey)
CPTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:(CPTimeInterval seconds, [target] id aTarget, [selector] SEL aSelector, [userInfo] id userInfo, [repeats] BOOL shouldRepeat)
A timer object that can send a message after the given time interval.
Represents an operation that can be run in an CPOperationQueue.
id functionOperationWithFunction:(JSObject jsFunction)
Represents an operation queue that can run CPOperations.