The GSOperation class provides for traditional messaging
to one or more objects, where the message has zero or one
object argument and returns an object. The
constructor creates an instance with one such
item, but you can add more items describing messagng to
be performed in sequences. The instance methods in
this class may be used either before the operation is
added to a queue or by the delegate handling a
-shouldStopOperation:afterItemAt:completedWith:
message.
The NSBlockOperation class is inherently non-portable due
to its dependency on a single compiler. Any portable code
with a use for similar functionality should use the
NSInvocationBlock instead.
Adds a dependency to the receiver. The receiver
is not considered ready to execute until all of its
dependencies have finished executing.
You must not add a particular object to the receiver
more than once. You must not create loops of
dependencies (this would cause deadlock).
Marks the operation as cancelled (causes subsequent
calls to the
-isCancelled
method to return YES). This does
not directly cause the receiver to stop executing... it
is the responsibility of the receiver to call
-isCancelled
while executing and act accordingly. If an
operation in a queue is cancelled before it
starts executing, it will be removed from the queue
(though not necessarily immediately).
Calling this method on an object which has already
finished executing has no effect.
This method returns YES if the receiver
handles its own environment or threading rather
than expecting to run in an evironment set up
elsewhere (eg, by an
NSOperationQueue
instance). The default implementation
returns NO.
This method should return YES if the
receiver has finished executing its
-main
method (irrespective of whether the execution
completed due to cancellation, failure, or
success).
This method should return YES when the
receiver is ready to begin executing. That is, the
receiver must have no dependencies which have not
finished executing. Also returns
YES if the operation has been cancelled
(even if there are unfinished dependencies).
An executing or finished operation is also considered to
be ready.
This is the method which actually performs the
operation... the default implementation does
nothing. You MUST ensure that your
implemention of
-main
does not raise any exception or call
[NSThread +exit]
as either of these will terminate the operation
prematurely resulting in the operation never
reaching the
-isFinished
state. If you are writing a concurrent
subclass, you should override
-start
instead of (or as well as) the
-main
method.
Sets the priority for the receiver. If the
value supplied is not one of the predefined queue
priorities, it is converted into the next
available defined value moving towards
NSOperationQueuePriorityNormal.
Sets the thread priority to be used while executing
then -main
method.
The priority change is implemented in the
-start
method, so if you are replacing
-start
you are responsible for managing this. The valid
range is 0.0 to 1.0
This method is called to start execution of the
receiver.
For concurrent operations, the subclass must override
this method to set up the environment for the
operation to execute, must execute the
-main
method, must ensure that
-isExecuting
and
-isFinished
return the correct values, and must manually call
key-value-observing methods to notify
observers of the state of those two properties.
The subclass implementation must NOT call
the superclass implementation.
For non-concurrent operations, the default
implementation of this method performs all
the work of setting up environment etc, and the
subclass only needs to override the
-main
method.
This method blocks the current thread until the
receiver finishes. Care must be taken to
avoid deadlock... you must not call this method from
the same thread that the receiver started in.
An NSOperationQueue manages a number of NSOperation
objects, scheduling them for execution and managing
their dependencies. Depending on the configuration of
the queue, operations may be executed concurrently or
serially. Worker threads are named
"NSOperationQ_<number>"
by default, but you can set a name for the queue using the
-setName:
method. The suffix "_<number>"" is
automatically added to the thread name.
Sets the number of concurrent operations permitted.
The default
(NSOperationQueueDefaultMaxConcurrentOperationCount)
means that the queue should decide how many it does
based on system load etc.
Sets the underlying dispatch queue. Throws
`NSInvalidArgumentException`
if: - The argument is `NULL` - There are operations in
the queue `(operationCount > 0)` - The argument is the
value returned by `dispatch_get_main_queue()`
Called on completion of the whole operation. This
notifies the delegate that the entire operation
has completed, but provides no information about
whether the operation did its job successfully or
not.
Called on completion of each item in a
GSOperation
, after sending a message (making a target perform a
selector). The result will
be either the return value of that message, or the
exception raised by that message. The
delegate may return YES to indicate
that processing of the operation as a whole should
complete without proceding to any items after
the one which just completed.
Sets the delegate that will be messaged when the
operation has finished. The operation uses a weak
reference to the delegate, it does not retain it.
Use this rather than
-setCompletionBlock:
(do not attempt to use both).