Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when removing condition dependencies #309

Merged
merged 2 commits into from May 15, 2016

Conversation

danthorpe
Copy link
Member

Since refactoring OperationCondition into Condition which is an Operation subclass, there is now an issue where any condition dependencies are executed immediately (well upon adding to the queue), which is not the desired behaviour.

@danthorpe danthorpe self-assigned this May 7, 2016
@danthorpe danthorpe added the bug label May 7, 2016
@danthorpe danthorpe added this to the 3.0 milestone May 7, 2016
@danthorpe danthorpe changed the title Conditions dependencies do not wait for Operation to "start" Error when removing condition dependencies May 15, 2016
The issue is that ComposedCondition must remove the dependency on its composed condition too.
@danthorpe danthorpe merged commit 9d2b41b into development May 15, 2016
@danthorpe danthorpe deleted the feature/OPR_309_condition_dependencies branch May 18, 2016 20:50
danthorpe added a commit that referenced this pull request Jul 9, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* [3.0.0]: Sets the version to 3.0.0

* [3.0.0]: Updates unavailable method message

* [3.0.0]: Updates license for 2016

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* [3.0.0]: Updates the Changelog

* [3.0.0]: Fixes linting issue related to OpenInSafariOperation
danthorpe added a commit that referenced this pull request Aug 7, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* [3.1.0]: Sets the version to 3.1.0

* [3.1.0]: Updates the CHANGELOG

* [3.1.0]: Renames jazzy config

* [3.1.0]: Removes the doc url link

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* [3.1.0]: Fixes issue in the Podspec

* [3.1.0]: Switches out Jazzy config file for JSON version

* [3.1.0]: Fixes whitespace issues
danthorpe added a commit that referenced this pull request Aug 29, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* [3.2.0]: Updates the CHANGELOG

* [3.2.0]: Sets the version to 3.2.0

* [3.2.0]: Updates the CHANGELOG
danthorpe added a commit that referenced this pull request Aug 29, 2016
* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* 3.1.1 (#411)


* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* [3.1.1]: Adds CHANGELOG

* [3.1.1]: Updates version

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* 3.2.0 (#431)

* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* [3.2.0]: Updates the CHANGELOG

* [3.2.0]: Sets the version to 3.2.0

* [3.2.0]: Updates the CHANGELOG

* [OPR-440]: Fixes iOS test target
danthorpe added a commit that referenced this pull request Sep 8, 2016
* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* 3.1.1 (#411)


* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* [3.1.1]: Adds CHANGELOG

* [3.1.1]: Updates version

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* 3.2.0 (#431)

* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* [3.2.0]: Updates the CHANGELOG

* [3.2.0]: Sets the version to 3.2.0

* [3.2.0]: Updates the CHANGELOG

* [OPR-440]: Fixes iOS test target
danthorpe added a commit that referenced this pull request Sep 8, 2016
* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* 3.1.1 (#411)


* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* [3.1.1]: Adds CHANGELOG

* [3.1.1]: Updates version

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* 3.2.0 (#431)

* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* [3.2.0]: Updates the CHANGELOG

* [3.2.0]: Sets the version to 3.2.0

* [3.2.0]: Updates the CHANGELOG

* [OPR-440]: Fixes iOS test target
danthorpe added a commit that referenced this pull request Sep 14, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* Resolving Unmanaged<CFErrorRef> warning (#452)

CFErrorRef is a typealias for CFError that is a struct. Unmanaged is for objects only.wq

* FIX: macOS deployment target should be 10.10 (Swift 2.2) (#453) (#454)

* Separate out extra features from podspec (#456)

* [OPR-456]: Removes Calendar, Location, Passbook, Photos etc from standard framework

* [OPR-456]: Reorders subspecs a bit

* [OPR-456]: Sorts out Extension compatible project

* [OPR-456]: Removes Slather step

* [OPR-456]: Fixes podspec error

* [swift/2.3]: Updates to Swift 2.3

* [swift/2.3]: Fixes issue with selecting agent with swift version.

* [swift/2.3]: Sets the developer directory

* [swift/2.3]: Sets the Swift version

* [swift/2.3]: Gets SWIFT_VERSION set correctly at tests.

Also had to prefix Dispatch. to a bunch of dispatch_async calls.

* [swift/2.3]: Disables StressTests

* [swift/2.3]: Removes slather

* [swift/2.3]: Removes Slather properly

* [swift/2.3]: Updates project to latest warnings

* [swift/2.3]: Updates for Swift 2.3

* [swift/2.3]: Updates .gitignore

* Supports new CloudKit operations in iOS 10 / macOS 10.12 (#406)

* Add new CloudKit associatedtypes, and missing/new CKOperation parameters.

* Add CKFetchAllChanges protocol

* Add support for CKAcceptSharesOperation

* Add support for CKDiscoverAllUserIdentitiesOperation

* Add support for CKDiscoverUserIdentitiesOperation

* Add support for CKFetchDatabaseChangesOperation

* Add support for CKFetchRecordZoneChangesOperation

* Add support for CKFetchShareMetadataOperation

* Add support for CKFetchShareParticipantsOperation

* Add test operations for the new CKOperations to CloudKitOperationTests

* Add tests

* Add tests

* Add tests

* Add tests

* Add availability markers for deprecated CKOperations

* Fix watchOS support for CloudKitInterface.swift

* Disable swiftlint file_length warning for CloudKitInterface.swift

* Remove unneeded associated Error type declaration from the specific protocols

* CKDiscoverAllUserIdentitiesOperation is unavailable on tvOS

* Make public some properties that should be public

* Integrating recent changes from swift/2.2 branch into swift/2.3 branch (#424)

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* 3.1.1 (#411)

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* [3.1.1]: Adds CHANGELOG

* [3.1.1]: Updates version

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Updates swift/2.3 with 3.2.0 release (#440)

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* 3.1.1 (#411)


* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* [3.1.1]: Adds CHANGELOG

* [3.1.1]: Updates version

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift version explicitly

* [OPR-427]: Puts the coveralls environment vars back

* [OPR-427]: Updates README to point to swift/2.2 coverage badge

* [OPR-427]: Fixes coverage badge

* Removes offending OpenInSafariOperationTests (#434)

Fixes #432

* Replaces some instances of String interpolation (#435)

* 3.2.0 (#431)

* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Unschedules dispatch queue when stopping notifier (#360) (#410)

* Makes Operation's conditions property public accessible (#412)

* Fixes crash when accessing deallocated self (#416) (#417)

* fix: Crash when self was destroyed, issue #416

* ConditionOperation "executed before operation set" assertion fix (#420)

Fixes #415. 

* [OPR-415]: Replace the assertionFailure if Condition.operation == nil with a log statement

Previously, if a ConditionOperation’s `operation` var was nil when it executed, the following assertionFailure occurred:
`assertionFailure("ConditionOperation executed before operation set.”)`

However, this could also occur if the weak `operation` var was set, but the operation cancelled/finished/went away before the ConditionOperation was executed.

Thus the `assertionFailure` has been replaced with a log statement.

* [OPR-415]: Add a new StressTest case that covers some ConditionOperation race conditions and thread safety

* Fix for NetworkObserver Timer not properly handling cancellation (#344) (#421)

The value of `isCancelled` was being captured by the `dispatch_after` block at `init`, and thus the check always passed and the Timer's handler was always invoked (even if `Timer.cancel()` was called).
This was resolved by making `Timer` a reference type.

* Flickering / robustness fixes for NetworkObserver / NetworkIndicatorController (#422)

Previously, NetworkIndicatorController would not ensure that any existing Timer was cancelled when another observed (network) operation started prior to the Timer firing.

This resulted in potential flickering of the network activity indicator (or inaccurate state, where it disappeared too quickly) in some cases.

* Tests may randomly fail due to a bug in expectation fulfillment (#419)

Fixed a number of places where `XCTestExpectation.fulfill()` was not being called on the main thread:

* Main-thread expectation fulfillment in OperationTests.addCompletionBlockToTestOperation()

* Main-thread expectation fulfillment in BasicTests.swift

* Main-thread expectation fulfillment in StressTests.swift

* Increase StressTest timeout for CI

* Recode `test__completion_blocks` StressTest to use a dispatch_group instead of an expectation for every TestOperation.

* Main-thread expectation fulfillment in BlockConditionTests.swift

* Main-thread expectation fulfillment in CloudCapabilitiesTests.swift

* Main-thread expectation fulfillment in GroupOperationTests.swift

* Main-thread expectation fulfillment in NegatedConditionTests.swift

* Main-thread expectation fulfillment in RemoteNotificationConditionTests.swift

* Adjust StressTest to try to fix CI

`test__completion_blocks` used a `BlockOperation { }`, which (currently) defaults to dispatching the block to the main queue. Changing this to a `BlockOperation(block:)`, which uses the queue on which the BlockOperation is executed.

* Enhance internal testing `waitForOperation` methods to support an optional timeout parameter

* Increase timeouts for some StressTests to fix CI

* Fix `Operation.cancelWithErrors()` thread-safety (#423)

* Fix `Operation.cancelWithErrors()` thread-safety

The potential existed for `Operation.cancelWithErrors()` to result in an assert due to an illegal state transition from `.Pending` => `.Finishing` while `cancelled == false`.

This was fixed by ensuring that the additional cancellation errors are appended to the `_internalErrors` array at the same time that `_cancelled` is set to `true` (i.e. within the same acquisition of the lock).

* Added StressTest of `Operation.cancelWithErrors()`

* Rewrite `test__dependent_operations_always_run` to use a dispatch_group instead of an expectation for every BlockOperation

This speeds up the test, and resolves possible main-thread-stall issues running the test.

* Improve CI pipeline for Swift 2.2 (#427)

* [OPR-427]: Adds iOS-Simulator metadata to pipeline

* [OPR-427]: Refactors pipeline to set Swift …
danthorpe added a commit that referenced this pull request Sep 16, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* [4.0.0-beta-1]: Sets the version

* [4.0.0-beta-1]: Fixes Fastfile

* [4.0.0-beta-1]: Deletes Operations project

* [4.0.0-beta-1]: Removes the Operations fastlane lanes

* [4.0.0-beta-1]: Removes Operations scripts

* [4.0.0-beta-1]: Refactors the pipeline commands

* Revert "[4.0.0-beta-1]: Refactors the pipeline commands"

This reverts commit d83eae7.

* [4.0.0-beta-1]: Updates the Changelog
danthorpe added a commit that referenced this pull request Oct 13, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* [4.0.0-beta-3]: Fixes a release Swift compile bug

* [4.0.0-beta-3]: Updates environment dependencies

* [4.0.0-beta-3]: Mobile framework is only iOS

* [4.0.0-beta-3]: Removes need for debug build of ProcedureKit inside TestingProcedureKit

This does require us to expose the exclusivity manager, and a `__tearDownForUnitTesting()` API - but it’s a minor thing compared with Carthage support.

* [4.0.0-beta-3]: Gets all targets building via Carthage

$ carthage build --no-skip-current
*** xcodebuild output can be found in /var/folders/36/tvprlgf11qg3c4nh0675qgz00000gn/T/carthage-xcodebuild.j1Ofvs.log
*** Building scheme "Stress Tests" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKit" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKitCloud" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKitMobile" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKitMac" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKitLocation" in ProcedureKit.xcodeproj
*** Building scheme "ProcedureKitTV" in ProcedureKit.xcodeproj
*** Building scheme "TestingProcedureKit" in ProcedureKit.xcodeproj
Sansa:ProcedureKit daniel$

* [4.0.0-beta-3]: Updates CHANGELOG

* [4.0.0-beta-3]: Fixes the podspec version
danthorpe added a commit that referenced this pull request Oct 30, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
#293
#358 (comment)

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* Adds AnyProcedure (#516)

* [OPR-516]: Removes import foundation

This is done by the prefix header

* [OPR-516]: Adds AnyProcedure

* [OPR-516]: Uses the correct underlying queue throughout AnyProcedure

* Fixes regression of failing release build (#518)

* Renames AuthorizationStatusProtocol to AuthorizationStatus (#519)

* Renames capability reated procedures (#520)

* Renames attach(condition: Condition) to add (#521)

* Adds Capability.CloudKit (#523)

* [OPR-523]: Adds Capability.CloudKit

* [OPR-523]: Enables CI builds for CloudKit stuff on iOS and tvOS

* Adds ProcedureKitNetwork framework (#524)

* [OPR-524]: Adds ProcedureKitNetwork framework

* [OPR-524]: Adds Network to CI jobs

* [OPR-524]: Renames Stress Tests job

* [OPR-524]: Shares the network scheme

* [OPR-524]: Imports Foundation instead of Cocoa

* [OPR-524]: Forces Stress Tests onto a non-simulator agent

* Adds NetworkDataProcedure (#525)

* [OPR-525]: Adds NetworkDataProcedure

* [OPR-525]: Fixes up some unit tests

* [OPR-525]: Adds missing test coverage

* Moves TestableNetwork into TestingProcedureKit framework (#526)

* Refactors injectDependency API to be an extension on ProcedureProtocol instead. (#527)

* Adds transform block result injection API (#528)

* [OPR-528]: Refactors result injection

Uses an intermediatory injectResult(from: via:) API, which allows the caller to provide a throwing block to transform the result into the requirement.

* [OPR-528]: Removes unneeded return

* [OPR-528]: Fixes error in ProcedureKitLocation

* Adds default empty implementations some queue delegate methods (#531)

Only added the will-do-something ones.

Fixes #530

* Adds space in the repo for presentations  (#533)

* [OPR-533]: Adds CocoaHeads Stockholm talk

Contact @danthorpe if you want the original Keynote file.

* [OPR-533]: Adds Sky-UK iOS Community Talk

* [OPR-533]: Adds a presentations README

* Disables the log for AnyProcedure (#534)

* Fixes bug where GroupProcedure collects errors from children after its been cancelled (#532)

* [OPR-532]: Adds failing test

* [OPR-532]: Checks cancelled state of the group

We can exit this delegate callback early if the group has already been cancelled.

* [OPR-532]: Removes default implementation of willFinish

It seems that adding default implementations here causes some odd behaviour / intermittent crash where this is overwritten in the QueueDelegate.

* [OPR-532]: Fixes a unit test which is now mis-counting errors.

* Adds .then { } API (#536)

* [OPR-176]: Adds then extension on Operation

* [OPR-176]: Implements .then { } API

* [OPR-176]: Adds enqueue method to a collection of Operations

* [OPR-176]: Fixes header docs

* Removes default argument for session in NetworkDataProcedure (#538)

* Tweaks the cancel block procedure stress tests (#539)

There might be an underlying issue. As normally a batch of 10_000 finishing in ~ 5 seconds. But sometimes fails because it times out, meaning that an expectation is not getting fulfilled.

* Moves ProcedureKit imports to umbrella headers (#540)

* [OPR-540]: Putting the appropriate imports into umbrella headers

* [OPR-540]: Fixing issues with importing ProcedureKit into TestingProcedureKit

* Updates ProcedureKit podspec with subspecs (#508)

* [OPR-508]: Lints podspec without an warnings or errors.

* [OPR-508]: Fixes errors running tests

* Adds ResilientNetworkProcedure  (#537)

* [OPR-537] Adds ResilientNetworkProcedure

* [OPR-537]: Updates retry request with error code

* [OPR-537]: Adds edge case for ResilientNetworkProcedure

In some situations, the HTTP status code might well require (depending on the behaviour) a retry.

* [OPR-537]: Fixes simple unit tests

* Refactor ResultInjection to use PendingValue enum (#541)

* [OPR-541]: Refactors ResultInjectionProtocol to use PendingValue enum

* [OPR-541]: Renames ResultInjectionProtocol to ResultInjection

* Fixes BlockProcedure stress tests (#544)

* [OPR-544]: Fix test__cancel_block_procedure() failures

It was possible for the testing BlockProcedure to finish prior to the
`block.cancel()` call, which would result in some of the
BlockProcedures never cancelling (as they had finished first), and
a failing test.
Fixed by using a semaphore inside the BlockProcedure’s block.
Additionally, the test now waits for all BlockProcedures to cancel
*and* finish.

* [OPR-544]: Added a new stress test for BlockProcedure cancelling & finishing behavior (allowing for possible races between cancelling and finishing)

* Fixes ExclusivityManager synchronization bug (#545)

Fixes #543 

The ExclusivityManager was using `DispatchQueue.initiated`, which
returns a global **concurrent** queue, however its internals are
dependent upon **serial** execution of add/remove.
Modified to use a serial queue.

* Adds ResultProcedure and overloads injectResult(from:) (#546)

* Adds HTTPResult<Payload> (#547)

* Fix test crashes caused by QueueTestDelegate (#549)

QueueTestDelegate was not thread-safe. This could result in crashes running random tests.
Fixed by making QueueTestDelegate’s methods thread-safe.

* Adds ProcedureKitTestCase wait function that takes an array (#552)

* Adds TestingProcedureKit podspec (#553)

* Adds Mutual Exclusivity concurrency testing (#550)

* Add ConcurrencyTestCase

Exposes functionality to test operation concurrency.

* Add Mutual Exclusivity concurrency tests

* Refactored ConcurrencyTestCase

* Refactored ConcurrencyTestCase

* Adds didExecuteObserver (#554)

* [OPR-554]: Adds code with failing test

* [OPR-554]: Calls didExecuteObservers

* [OPR-554]: Fixes a typo

* [OPR-554]: Adds some documentation to the DidExecuteObserver

* Fixes mistake in Fastfile (#557)

* [OPR-557]: Fixes error in Fastfile

* [OPR-557]: Removes duplicate scan

I remember now, as part of location, we used to build Mobile too - because there was a dependency on iOS. But this has since been removed.

* Fixes release configuration issues with Xcode 8.1 (#559)

Fixes #548 

* [OPR-548]: Fixes issue with Xcode 8.1 release configuration

* [OPR-548]: Fixes some SwiftLint warnings.

* [OPR-548]: Fixes Xcode project warnings in Xcode 8.1

* Adds GroupProcedure concurrency tests (#556)

* Add GroupConcurrencyTestCase

* Add GroupProcedure.maxConcurrentOperationCount tests

* [4.0.0.beta.4]: Sets the version to 4.0.0.beta.4

* [4.0.0.beta.4]: Updates CHANGELOG

* [4.0.0.beta.4]: Fixes formatting of CHANGELOG
danthorpe added a commit that referenced this pull request Nov 28, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* Adds AnyProcedure (#516)

* [OPR-516]: Removes import foundation

This is done by the prefix header

* [OPR-516]: Adds AnyProcedure

* [OPR-516]: Uses the correct underlying queue throughout AnyProcedure

* Fixes regression of failing release build (#518)

* Renames AuthorizationStatusProtocol to AuthorizationStatus (#519)

* Renames capability reated procedures (#520)

* Renames attach(condition: Condition) to add (#521)

* Adds Capability.CloudKit (#523)

* [OPR-523]: Adds Capability.CloudKit

* [OPR-523]: Enables CI builds for CloudKit stuff on iOS and tvOS

* Adds ProcedureKitNetwork framework (#524)

* [OPR-524]: Adds ProcedureKitNetwork framework

* [OPR-524]: Adds Network to CI jobs

* [OPR-524]: Renames Stress Tests job

* [OPR-524]: Shares the network scheme

* [OPR-524]: Imports Foundation instead of Cocoa

* [OPR-524]: Forces Stress Tests onto a non-simulator agent

* Adds NetworkDataProcedure (#525)

* [OPR-525]: Adds NetworkDataProcedure

* [OPR-525]: Fixes up some unit tests

* [OPR-525]: Adds missing test coverage

* Moves TestableNetwork into TestingProcedureKit framework (#526)

* Refactors injectDependency API to be an extension on ProcedureProtocol instead. (#527)

* Adds transform block result injection API (#528)

* [OPR-528]: Refactors result injection

Uses an intermediatory injectResult(from: via:) API, which allows the caller to provide a throwing block to transform the result into the requirement.

* [OPR-528]: Removes unneeded return

* [OPR-528]: Fixes error in ProcedureKitLocation

* Adds default empty implementations some queue delegate methods (#531)

Only added the will-do-something ones.

Fixes #530

* Adds space in the repo for presentations  (#533)

* [OPR-533]: Adds CocoaHeads Stockholm talk

Contact @danthorpe if you want the original Keynote file.

* [OPR-533]: Adds Sky-UK iOS Community Talk

* [OPR-533]: Adds a presentations README

* Disables the log for AnyProcedure (#534)

* Fixes bug where GroupProcedure collects errors from children after its been cancelled (#532)

* [OPR-532]: Adds failing test

* [OPR-532]: Checks cancelled state of the group

We can exit this delegate callback early if the group has already been cancelled.

* [OPR-532]: Removes default implementation of willFinish

It seems that adding default implementations here causes some odd behaviour / intermittent crash where this is overwritten in the QueueDelegate.

* [OPR-532]: Fixes a unit test which is now mis-counting errors.

* Adds .then { } API (#536)

* [OPR-176]: Adds then extension on Operation

* [OPR-176]: Implements .then { } API

* [OPR-176]: Adds enqueue method to a collection of Operations

* [OPR-176]: Fixes header docs

* Removes default argument for session in NetworkDataProcedure (#538)

* Tweaks the cancel block procedure stress tests (#539)

There might be an underlying issue. As normally a batch of 10_000 finishing in ~ 5 seconds. But sometimes fails because it times out, meaning that an expectation is not getting fulfilled.

* Moves ProcedureKit imports to umbrella headers (#540)

* [OPR-540]: Putting the appropriate imports into umbrella headers

* [OPR-540]: Fixing issues with importing ProcedureKit into TestingProcedureKit

* Updates ProcedureKit podspec with subspecs (#508)

* [OPR-508]: Lints podspec without an warnings or errors.

* [OPR-508]: Fixes errors running tests

* Adds ResilientNetworkProcedure  (#537)

* [OPR-537] Adds ResilientNetworkProcedure

* [OPR-537]: Updates retry request with error code

* [OPR-537]: Adds edge case for ResilientNetworkProcedure

In some situations, the HTTP status code might well require (depending on the behaviour) a retry.

* [OPR-537]: Fixes simple unit tests

* Refactor ResultInjection to use PendingValue enum (#541)

* [OPR-541]: Refactors ResultInjectionProtocol to use PendingValue enum

* [OPR-541]: Renames ResultInjectionProtocol to ResultInjection

* Fixes BlockProcedure stress tests (#544)

* [OPR-544]: Fix test__cancel_block_procedure() failures

It was possible for the testing BlockProcedure to finish prior to the
`block.cancel()` call, which would result in some of the
BlockProcedures never cancelling (as they had finished first), and
a failing test.
Fixed by using a semaphore inside the BlockProcedure’s block.
Additionally, the test now waits for all BlockProcedures to cancel
*and* finish.

* [OPR-544]: Added a new stress test for BlockProcedure cancelling & finishing behavior (allowing for possible races between cancelling and finishing)

* Fixes ExclusivityManager synchronization bug (#545)

Fixes #543 

The ExclusivityManager was using `DispatchQueue.initiated`, which
returns a global **concurrent** queue, however its internals are
dependent upon **serial** execution of add/remove.
Modified to use a serial queue.

* Adds ResultProcedure and overloads injectResult(from:) (#546)

* Adds HTTPResult<Payload> (#547)

* Fix test crashes caused by QueueTestDelegate (#549)

QueueTestDelegate was not thread-safe. This could result in crashes running random tests.
Fixed by making QueueTestDelegate’s methods thread-safe.

* Adds ProcedureKitTestCase wait function that takes an array (#552)

* Adds TestingProcedureKit podspec (#553)

* Adds Mutual Exclusivity concurrency testing (#550)

* Add ConcurrencyTestCase

Exposes functionality to test operation concurrency.

* Add Mutual Exclusivity concurrency tests

* Refactored ConcurrencyTestCase

* Refactored ConcurrencyTestCase

* Adds didExecuteObserver (#554)

* [OPR-554]: Adds code with failing test

* [OPR-554]: Calls didExecuteObservers

* [OPR-554]: Fixes a typo

* [OPR-554]: Adds some documentation to the DidExecuteObserver

* Fixes mistake in Fastfile (#557)

* [OPR-557]: Fixes error in Fastfile

* [OPR-557]: Removes duplicate scan

I remember now, as part of location, we used to build Mobile too - because there was a dependency on iOS. But this has since been removed.

* Fixes release configuration issues with Xcode 8.1 (#559)

Fixes #548 

* [OPR-548]: Fixes issue with Xcode 8.1 release configuration

* [OPR-548]: Fixes some SwiftLint warnings.

* [OPR-548]: Fixes Xcode project warnings in Xcode 8.1

* Adds GroupProcedure concurrency tests (#556)

* Add GroupConcurrencyTestCase

* Add GroupProcedure.maxConcurrentOperationCount tests

* Fixes registrar typo (#562)

* Adds NetworkDownloadProcedure. (#565)

The implementation for class and test is largely inspired by
`NetworkDataProcedure` class.

* Adds NetworkUploadProcedure. (#567)

* Add NetworkUploadProcedure.

The implementation class and test has been largely inspired by
`NetworkDataProcedure`.

The requirement type is currently a pending value of a tuple.
Maybe would it make more sense to create a dedicated struct to add more
clarity in the case of dependencies injection ?

* Use an `HTTPRequirement` struct for requirement.

As discussed, an `HTTPRequirement` struct is used instead of a tuple.

* Fixes Condition to support ResultInjection (#566)

* [OPR-566]: Replaces Condition result with PendingValue<ConditionResult>

* [OPR-566]: Refactors how conditions are evaluated

This fixes a existing issue where the ConditionEvaluation enum was basically just like ConditonResult, except that it could hold an array of errors.

This has been resolved by using an internal error type `ProcedureKitError.FailedConditions` to collect multiple errors from failed conditons, so that we can reduce a sequence of `ConditionResult`s into a single one.

* [OPR-566]: Explicitly adds a Result typealias

* [OPR-566]: Fixes error where cancelled conditions would throw a fatal error.

* [OPR-566]: Removes verbose log

* Adds ProcessProcedure. (#570)

* Add ProcessProcedure.

The class has been largely inspired by the original `TaskOperation`.
Refers to #568.

* Apply requested changes.

Correctly implement `Equatable` for sub-error enum.
Use camel case for the enum.
Fix closure self semantics.

* Calls TestableReverseGeocoder completionHandler on the main queue (#572)

* Improves performance of adding observers

* Procedure.add(observer:) performance tweak

Append directly to the protected observers array.

* Fix swiftlint `variable_name` warning

* Makes ProcedureQueue.add(operation: Operation) method open (#578)

* Fixes NetworkObserver thread-safety (#576) (#577)

* Fix NetworkObserver thread-safety

By fixing NetworkActivityController `start()`/`stop()` thread-safety.
(And making private methods/variables private.)

* NetworkObserver test fixes

* Reduce test delay

* Additional GroupProcedure tests (#579)

* Adds CloudKitProcedure (#542)

* [OPR-542]: Adds shell of CloudKit files

* [OPR-542]: Adds extensions for CKOperation

* [OPR-542]: Adds extensions for CKDatabaseOperation

* [OPR-542]: Adds extensions for CKAcceptSharesOperation

* [OPR-542]: Adds extensions for CKDiscoverAllContactsOperation

* [OPR-542]: Adds extensions for CKDiscoverAllUserIdentifiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserInfosOperation

* [OPR-542]: Adds extensions for CKFetchDatabaseChanges

* [OPR-542]: Adds extensions for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds extensions for CKFetchRecordChangesOperation

* [OPR-542]: Moves the interface into the extension files

* [OPR-542]: Fixes dispatchQueue

* [OPR-542]: Adds extensions to CKFetchRecordsOperation

* [OPR-542]: Adds extensions for CKFetchRecordZoneChangesOperation

* [OPR-542]: Removes unnecessary public properties

* [OPR-542]: Adds extensions for CKFetchRecordZonesOperation

* [OPR-542]: Adds extensions for CKFetchShareMetadataOperation

* [OPR-542]: Adds extensions for CKFetchShareParticipantsOperation

* [OPR-542]: Adds extensions for CKFetchSubscriptionsOperation

* [OPR-542]: Adds extensions for CKMarkNotificationsReadOperation

* [OPR-542]: Adds extensions for CKModifyBadgeOperation

* [OPR-542]: Adds extensions for CKModifyRecordsOperation

* [OPR-542]: Adds extensions for CKModifyRecordZonesOperation

* [OPR-542]: Adds extensions for CKModifySubscriptionsOperation

* [OPR-542]: Adds extensions for CKQueryOperation

* [OPR-542]: Adds missing APIs for error handlers

* [OPR-542]: Adds testable CK operation classes

* [OPR-542]: Adds tests for CKOperation, CKDatabaseOperation and CKAcceptSharesOperation

* [OPR-542]: Removes missing test cases from tvOS

* Small typo fix

* Adds tests for CKDiscoverAllContactsOperation

* Adds tests for CKDiscoverAllUserIdentitiesOperation

* Adds tests for CKDiscoverUserIdentitiesOperation

* Adds tests for CKDiscoverUserInfosOperation

* [OPR-542]: Adds tests for CKFetchAllChanges protocol

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordsOperation

* [OPR-542]: Added missing `recordZoneFetchCompletionBlock` for CKFetchRecordZoneChangesOperationProtocol extensions

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Minor typo fix

To follow the original API naming, change
`setMarkNotificationReadCompletionBlock` to
`setMarkNotificationsReadCompletionBlock`.

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds tests for CKModifySubscriptionsOperation

* [OPR-542]: Adds tests for CKQueryOperation

* [OPR-542]: Fixes whitespace in test cases

* [OPR-542]: Adds CloudKitProcedure<CKAcceptSharesOperation> tests

* [OPR-542]: Fixes tests on tvOS. Again.

* [OPR-542]: Adds tests for CKDiscoverAllContactsOperation

* [OPR-542]: Adds tests for CKDiscoverAllUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserInfosOperations

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Unifies testing of common properites

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds test for CKFetchRecordsOperation

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds test for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Fixes inconsistently named tests

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds test for CKModifySubscriptionsOperation

* [OPR-542]: Adds test for CKQueryOperation

* [OPR-542]: Adds tests which trigger default retry behavior

* [OPR-542]: Adds tests for set/get all errors handlers

* [OPR-542]: Adds tests for custom error handlers

* Adds Profiler (#573)

* Implement Profiler as specified in #569.

The implmentation is largely inspired by the original `Profiler.swift`
file.

* Add first set of tests.

The test has been largely inspired by the original tests classes.

I have a commented test taht fails. After trying to debug for a while, I
suspect maybe an issue inside GroupProcedure or the original
implementation.

* Apply requested changes.

Perform changes as requested.

* Adds public initialiser to HTTPRequirement (#586)

Declaring a constructor for the `HTTPRequirement` allows the
construction of the struct without any issue.

* Removes GroupProcedureObserver protocol (#583)

Instead ProcedureObserver takes over this responsibility.

* [OPR-574]: Cleans up white space & style for consistency

* [OPR-574]: Uncomments failing test

* [OPR-574]: Adds new API to ProcedureObserver protocol

* [OPR-574]: Removes temporary print statements

* [OPR-574]: Refactors to support willAdd & didAdd observer callbacks.

* [OPR-574]: Removes commented out line.

* [OPR-574]: Removes group observers.

* [OPR-574]: Removes extraneous logging in some tests

* [OPR-574]: Makes add(observer:) open for overriding

* [OPR-574]: Adds some documentation comments to public interfaces

* Supports Arbitrary mutual exclusion category names (#587)

Fixes #580.

* [OPR-580]: Supports arbitrary mutual exclusion category names

* [OPR-580]: Fixes default category for AuthorizedFor

* Adds NetworkReachableProcedure (#563)

* [OPR-563]: Adds Reachability functionality

* [OPR-563]: Adds additional files for testing support

* [OPR-563]: Adds tests for Reachability

* [OPR-563]: Adds basis of NetworkReachableProcedure

* [OPR-563]: Adds simple network reachability procedure tests

* [OPR-563]: Fixes issue with Protector write being synchronous.

* [OPR-563]: Refactors DeviceReachability slightly

* [OPR-563]: Changes Protector behavior back to be non-blocking

* [OPR-563]: Fixes Reachability.Device

* [OPR-563]: Adds NetworkProcedure and ProcedureKitNetworkError

* [OPR-563]: Fixes for network error tests

* [OPR-563]: Adds remaining tests for Reachable procedure

* [OPR-563]: Removes unnecessary logging

* Refactors produce API (#588)

* Add failing test

* Test tweaks

* Changes to Procedure.produce(operation:) handling

Fixes failing test case, and simplifies execution flow.
Changes `willEnqueue()` to `willEnqueue(on: ProcedureQueue)`.
`func produce(operation: Operation)` now throws.

* Ported additional test case from Operations 3.x.

* swiftlint tweak

* Fixed mobile tests.

* Adds missing equality cases for ProcedureKitError.Context (#591)

Fixes #589

* Supports merging collections of ResultInjection Procedures (#593)

* [OPR-593]: Adds gather and reduce APIs

* [OPR-593]: Removes the rethrows

While the nextPartialResult closure can throw, this error is not re-thrown. Instead, because this block is executed after the receiver’s procedures have all finished, the error means that the `ResultProcedure` will finish with an error.

* [OPR-593]: Adds test case for throwing closure

* [OPR-593]: Refactors gather() so that it is a specialization of new flatMap API

* Improves how stress tests are run in CI (#594)

* [OPR-594]: Updates pipeline queues

* [OPR-594]: Fixes yaml

* [OPR-594]: Disables Thread Sanitizer for Stress Tests

* [OPR-594]: Uses Release configuration for stress tests

* Fix StressTestCase Batch counters thread-safety (#555) (#596)

* Fixes public access levels for CKProcedure (#599)

* Fixes some RepeatProcedure thread-safety issues (#597)

Fix issues identified by an audit and Thread Sanitizer

* Fixes Procedure & Support thread-safety (#598)

* Change Protector.write() to be synchronous (and optionally return a value from the block)

Thread Sanitizer identified a data race caused by the combination of
the prior asynchronous `write()` and deinitialization.

* Explicitly `import Dispatch` in Support.swift

Fixes an occasional Xcode warning display glitch.

* Fix Protector.read() to no longer require an `escaping` block

* Adds back `Protector.write(_:completion:)`

Although, like the new write(_:) method, this is now synchronous.

* Wrap all properties of Procedure in a Protector to ensure thread-safety

`errors`, `observers`, `directDependencies`, `conditions` (and
associated methods) are now thread-safe

* Fix comment formatting

* Removes @testable import (#600)

Exposes NSLock and NSRecursiveLock extensions

* Add RepeatProcedure cancellation stress test (#602)

* Adds more GroupProcedure test coverage (#603)

* Additional / improved GroupProcedure test cases

* Remove unused private setter

* Refactors of Result Injection APIs (#601)

* [OPR-601]: Renamed PendingResult to PendingProfileResult

* [OPR-601]: Adds protocols for Input & Output

* [OPR-601]: Refactors for InputProcedure & OutputProcedure

* [OPR-601]: Refactors ReduceProcedure as a TransformProcedure subclass

* [OPR-601]: Refactoring for InputProcedure & OutputProcedure

* [OPR-601]: Refactoring Condition to use Result<Bool>

* [OPR-601]: Refactors ProcedureKitNetwork result injection

* [OPR-601]: Refactors Location for result injection

* [OPR-601]: Removes ResultInjection.swift

* [OPR-601]: Removes left over properties

* [OPR-601]: Tidies up ResultProcedure & TransformProcedure

* [OPR-601]: Adds finish(withResult:) API

* [OPR-601]: Refactors to use finish(withResult:)

* [OPR-601]: Renames HTTPRequirement & HTTPResult

* Renames Result to ProcedureResult (#605)

* [OPR-605]: Renames Result to ProcedureResult

Just to help with any interop issues with antitypical/Result

* [OPR-605]: Renames Result to ProcedureResult

* Adds AsyncBlockProcedure  (#606)

* [OPR-606]: Adds AsyncBlockProcedure

As a specialization of AsyncResultProcedure

* [OPR-606]: Moves async block tests into same file

* [OPR-606]: Adds AsyncTransformProcedure

* Adds @escaping marker to the FinishingBlock (#607)

* Fixes NetworkActivityController internal timer (#608)

* NetworkActivityController's delayed hide should occur on the queue

Fixes data race.

* Remove outdated test

* NetworkDataProcedure, NetworkDownloadProcedure, NetworkUploadProcedure thread-safety (#609)

* Adds NetworkProcedure (#561)

* [OPR-561]: Refactoring ResilientNetworkProcedure

- Supports request timeout
- Adds HTTPStatusCode where we only even consider retrying client or server errors.
- Adds some initial tests

* [OPR-561]: Refactors NetworkResilience

* [OPR-561]: Refactor to unify reachable & resilience network procedures

* [OPR-561]: Adds resilience error handling support

This is so that even if the network request “succeeds” but results in say, a server error, we will still trigger retries.

* [OPR-561]: Fixes typos

* Add missing imports to make Xcode happier (#611)

* Add explicit imports to the top of ProcedureKit files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitCloud files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitMobile files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitLocation files
This makes Xcode happier.

* Fixes BackgroundObserver data race (#614)

* Makes NetworkObserver cross-platform (#613)

* NetworkObserver and NetworkActivityController cross-platform work

On all platforms, the following initializers are available:
`NetworkObserver.init(controller: NetworkActivityController)`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0,
indicator: NetworkActivityIndicatorProtocol)`

To implement your own network activity indicator display, conform to
`NetworkActivityIndicatorProtocol`. NetworkActivityController ensures
that all accesses of the indicator’s `networkActivityIndicatorVisible`
property are serialized on the main queue.

On iOS (but *not* in application extensions), the following convenience
initializers are available that utilize `UIApplication.shared` to
display/hide the network activity indicator in the status bar:
`NetworkObserver.init()`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0)`
`NetworkActivityController.shared`

* [OPR-612]: Moves NetworkObserver into Network framework

* [OPR-612]: Moves NetworkObserver into ProcedureKit

Keeps iOS non-extension related elements in ProcedureKitMobile

* Add documentation

* Fixes BackgroundObserver on iOS 8.x (#615)

To support iOS < 9.0 and macOS < 10.11, NotificationCenter observers
**must** be properly removed, or a crash may result.

* Fixes DelayProcedure thread-safety (#616)

* Fixes to Location related procedures (#619)

* Capability.Location should set its registrar's delegate to nil on deinit.

CLLocationManager’s delegate is `unowned(unsafe)`, and we must ensure
it is set to nil before the object goes away. The only strong reference
to the delegate that Capability.Location sets is stored within
Capability.Location.

* LocationCapabilityTests tweaks

Explicitly set the test CLLocationManager’s `delegate` back to nil.
Explicitly wait on `capability.requestAuthorization` to fulfill an
expectation.

* ReverseGeocodeProcedureTests tweaks

* Fix an occasional crash running the Location tests

It seems there may be an edge case in CoreLocation triggered when
creating (and releasing) lots of CLLocationManager instances (as
previously happened when each test, using its own
TestableLocationServicesRegistrar, created a “fake” CLLocationManager).

Change `TestableLocationServicesRegistrar`’s “fake” CLLocationManager
(which is only used to populate a parameter in the delegate callbacks)
to a static class variable.

* Compiles out SystemConfiguration related stuff from watchOS (#621)

* [4.0.0.beta.5]: Beta 5
danthorpe added a commit that referenced this pull request Dec 16, 2016
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* Adds AnyProcedure (#516)

* [OPR-516]: Removes import foundation

This is done by the prefix header

* [OPR-516]: Adds AnyProcedure

* [OPR-516]: Uses the correct underlying queue throughout AnyProcedure

* Fixes regression of failing release build (#518)

* Renames AuthorizationStatusProtocol to AuthorizationStatus (#519)

* Renames capability reated procedures (#520)

* Renames attach(condition: Condition) to add (#521)

* Adds Capability.CloudKit (#523)

* [OPR-523]: Adds Capability.CloudKit

* [OPR-523]: Enables CI builds for CloudKit stuff on iOS and tvOS

* Adds ProcedureKitNetwork framework (#524)

* [OPR-524]: Adds ProcedureKitNetwork framework

* [OPR-524]: Adds Network to CI jobs

* [OPR-524]: Renames Stress Tests job

* [OPR-524]: Shares the network scheme

* [OPR-524]: Imports Foundation instead of Cocoa

* [OPR-524]: Forces Stress Tests onto a non-simulator agent

* Adds NetworkDataProcedure (#525)

* [OPR-525]: Adds NetworkDataProcedure

* [OPR-525]: Fixes up some unit tests

* [OPR-525]: Adds missing test coverage

* Moves TestableNetwork into TestingProcedureKit framework (#526)

* Refactors injectDependency API to be an extension on ProcedureProtocol instead. (#527)

* Adds transform block result injection API (#528)

* [OPR-528]: Refactors result injection

Uses an intermediatory injectResult(from: via:) API, which allows the caller to provide a throwing block to transform the result into the requirement.

* [OPR-528]: Removes unneeded return

* [OPR-528]: Fixes error in ProcedureKitLocation

* Adds default empty implementations some queue delegate methods (#531)

Only added the will-do-something ones.

Fixes #530

* Adds space in the repo for presentations  (#533)

* [OPR-533]: Adds CocoaHeads Stockholm talk

Contact @danthorpe if you want the original Keynote file.

* [OPR-533]: Adds Sky-UK iOS Community Talk

* [OPR-533]: Adds a presentations README

* Disables the log for AnyProcedure (#534)

* Fixes bug where GroupProcedure collects errors from children after its been cancelled (#532)

* [OPR-532]: Adds failing test

* [OPR-532]: Checks cancelled state of the group

We can exit this delegate callback early if the group has already been cancelled.

* [OPR-532]: Removes default implementation of willFinish

It seems that adding default implementations here causes some odd behaviour / intermittent crash where this is overwritten in the QueueDelegate.

* [OPR-532]: Fixes a unit test which is now mis-counting errors.

* Adds .then { } API (#536)

* [OPR-176]: Adds then extension on Operation

* [OPR-176]: Implements .then { } API

* [OPR-176]: Adds enqueue method to a collection of Operations

* [OPR-176]: Fixes header docs

* Removes default argument for session in NetworkDataProcedure (#538)

* Tweaks the cancel block procedure stress tests (#539)

There might be an underlying issue. As normally a batch of 10_000 finishing in ~ 5 seconds. But sometimes fails because it times out, meaning that an expectation is not getting fulfilled.

* Moves ProcedureKit imports to umbrella headers (#540)

* [OPR-540]: Putting the appropriate imports into umbrella headers

* [OPR-540]: Fixing issues with importing ProcedureKit into TestingProcedureKit

* Updates ProcedureKit podspec with subspecs (#508)

* [OPR-508]: Lints podspec without an warnings or errors.

* [OPR-508]: Fixes errors running tests

* Adds ResilientNetworkProcedure  (#537)

* [OPR-537] Adds ResilientNetworkProcedure

* [OPR-537]: Updates retry request with error code

* [OPR-537]: Adds edge case for ResilientNetworkProcedure

In some situations, the HTTP status code might well require (depending on the behaviour) a retry.

* [OPR-537]: Fixes simple unit tests

* Refactor ResultInjection to use PendingValue enum (#541)

* [OPR-541]: Refactors ResultInjectionProtocol to use PendingValue enum

* [OPR-541]: Renames ResultInjectionProtocol to ResultInjection

* Fixes BlockProcedure stress tests (#544)

* [OPR-544]: Fix test__cancel_block_procedure() failures

It was possible for the testing BlockProcedure to finish prior to the
`block.cancel()` call, which would result in some of the
BlockProcedures never cancelling (as they had finished first), and
a failing test.
Fixed by using a semaphore inside the BlockProcedure’s block.
Additionally, the test now waits for all BlockProcedures to cancel
*and* finish.

* [OPR-544]: Added a new stress test for BlockProcedure cancelling & finishing behavior (allowing for possible races between cancelling and finishing)

* Fixes ExclusivityManager synchronization bug (#545)

Fixes #543 

The ExclusivityManager was using `DispatchQueue.initiated`, which
returns a global **concurrent** queue, however its internals are
dependent upon **serial** execution of add/remove.
Modified to use a serial queue.

* Adds ResultProcedure and overloads injectResult(from:) (#546)

* Adds HTTPResult<Payload> (#547)

* Fix test crashes caused by QueueTestDelegate (#549)

QueueTestDelegate was not thread-safe. This could result in crashes running random tests.
Fixed by making QueueTestDelegate’s methods thread-safe.

* Adds ProcedureKitTestCase wait function that takes an array (#552)

* Adds TestingProcedureKit podspec (#553)

* Adds Mutual Exclusivity concurrency testing (#550)

* Add ConcurrencyTestCase

Exposes functionality to test operation concurrency.

* Add Mutual Exclusivity concurrency tests

* Refactored ConcurrencyTestCase

* Refactored ConcurrencyTestCase

* Adds didExecuteObserver (#554)

* [OPR-554]: Adds code with failing test

* [OPR-554]: Calls didExecuteObservers

* [OPR-554]: Fixes a typo

* [OPR-554]: Adds some documentation to the DidExecuteObserver

* Fixes mistake in Fastfile (#557)

* [OPR-557]: Fixes error in Fastfile

* [OPR-557]: Removes duplicate scan

I remember now, as part of location, we used to build Mobile too - because there was a dependency on iOS. But this has since been removed.

* Fixes release configuration issues with Xcode 8.1 (#559)

Fixes #548 

* [OPR-548]: Fixes issue with Xcode 8.1 release configuration

* [OPR-548]: Fixes some SwiftLint warnings.

* [OPR-548]: Fixes Xcode project warnings in Xcode 8.1

* Adds GroupProcedure concurrency tests (#556)

* Add GroupConcurrencyTestCase

* Add GroupProcedure.maxConcurrentOperationCount tests

* Fixes registrar typo (#562)

* Adds NetworkDownloadProcedure. (#565)

The implementation for class and test is largely inspired by
`NetworkDataProcedure` class.

* Adds NetworkUploadProcedure. (#567)

* Add NetworkUploadProcedure.

The implementation class and test has been largely inspired by
`NetworkDataProcedure`.

The requirement type is currently a pending value of a tuple.
Maybe would it make more sense to create a dedicated struct to add more
clarity in the case of dependencies injection ?

* Use an `HTTPRequirement` struct for requirement.

As discussed, an `HTTPRequirement` struct is used instead of a tuple.

* Fixes Condition to support ResultInjection (#566)

* [OPR-566]: Replaces Condition result with PendingValue<ConditionResult>

* [OPR-566]: Refactors how conditions are evaluated

This fixes a existing issue where the ConditionEvaluation enum was basically just like ConditonResult, except that it could hold an array of errors.

This has been resolved by using an internal error type `ProcedureKitError.FailedConditions` to collect multiple errors from failed conditons, so that we can reduce a sequence of `ConditionResult`s into a single one.

* [OPR-566]: Explicitly adds a Result typealias

* [OPR-566]: Fixes error where cancelled conditions would throw a fatal error.

* [OPR-566]: Removes verbose log

* Adds ProcessProcedure. (#570)

* Add ProcessProcedure.

The class has been largely inspired by the original `TaskOperation`.
Refers to #568.

* Apply requested changes.

Correctly implement `Equatable` for sub-error enum.
Use camel case for the enum.
Fix closure self semantics.

* Calls TestableReverseGeocoder completionHandler on the main queue (#572)

* Improves performance of adding observers

* Procedure.add(observer:) performance tweak

Append directly to the protected observers array.

* Fix swiftlint `variable_name` warning

* Makes ProcedureQueue.add(operation: Operation) method open (#578)

* Fixes NetworkObserver thread-safety (#576) (#577)

* Fix NetworkObserver thread-safety

By fixing NetworkActivityController `start()`/`stop()` thread-safety.
(And making private methods/variables private.)

* NetworkObserver test fixes

* Reduce test delay

* Additional GroupProcedure tests (#579)

* Adds CloudKitProcedure (#542)

* [OPR-542]: Adds shell of CloudKit files

* [OPR-542]: Adds extensions for CKOperation

* [OPR-542]: Adds extensions for CKDatabaseOperation

* [OPR-542]: Adds extensions for CKAcceptSharesOperation

* [OPR-542]: Adds extensions for CKDiscoverAllContactsOperation

* [OPR-542]: Adds extensions for CKDiscoverAllUserIdentifiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserInfosOperation

* [OPR-542]: Adds extensions for CKFetchDatabaseChanges

* [OPR-542]: Adds extensions for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds extensions for CKFetchRecordChangesOperation

* [OPR-542]: Moves the interface into the extension files

* [OPR-542]: Fixes dispatchQueue

* [OPR-542]: Adds extensions to CKFetchRecordsOperation

* [OPR-542]: Adds extensions for CKFetchRecordZoneChangesOperation

* [OPR-542]: Removes unnecessary public properties

* [OPR-542]: Adds extensions for CKFetchRecordZonesOperation

* [OPR-542]: Adds extensions for CKFetchShareMetadataOperation

* [OPR-542]: Adds extensions for CKFetchShareParticipantsOperation

* [OPR-542]: Adds extensions for CKFetchSubscriptionsOperation

* [OPR-542]: Adds extensions for CKMarkNotificationsReadOperation

* [OPR-542]: Adds extensions for CKModifyBadgeOperation

* [OPR-542]: Adds extensions for CKModifyRecordsOperation

* [OPR-542]: Adds extensions for CKModifyRecordZonesOperation

* [OPR-542]: Adds extensions for CKModifySubscriptionsOperation

* [OPR-542]: Adds extensions for CKQueryOperation

* [OPR-542]: Adds missing APIs for error handlers

* [OPR-542]: Adds testable CK operation classes

* [OPR-542]: Adds tests for CKOperation, CKDatabaseOperation and CKAcceptSharesOperation

* [OPR-542]: Removes missing test cases from tvOS

* Small typo fix

* Adds tests for CKDiscoverAllContactsOperation

* Adds tests for CKDiscoverAllUserIdentitiesOperation

* Adds tests for CKDiscoverUserIdentitiesOperation

* Adds tests for CKDiscoverUserInfosOperation

* [OPR-542]: Adds tests for CKFetchAllChanges protocol

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordsOperation

* [OPR-542]: Added missing `recordZoneFetchCompletionBlock` for CKFetchRecordZoneChangesOperationProtocol extensions

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Minor typo fix

To follow the original API naming, change
`setMarkNotificationReadCompletionBlock` to
`setMarkNotificationsReadCompletionBlock`.

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds tests for CKModifySubscriptionsOperation

* [OPR-542]: Adds tests for CKQueryOperation

* [OPR-542]: Fixes whitespace in test cases

* [OPR-542]: Adds CloudKitProcedure<CKAcceptSharesOperation> tests

* [OPR-542]: Fixes tests on tvOS. Again.

* [OPR-542]: Adds tests for CKDiscoverAllContactsOperation

* [OPR-542]: Adds tests for CKDiscoverAllUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserInfosOperations

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Unifies testing of common properites

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds test for CKFetchRecordsOperation

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds test for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Fixes inconsistently named tests

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds test for CKModifySubscriptionsOperation

* [OPR-542]: Adds test for CKQueryOperation

* [OPR-542]: Adds tests which trigger default retry behavior

* [OPR-542]: Adds tests for set/get all errors handlers

* [OPR-542]: Adds tests for custom error handlers

* Adds Profiler (#573)

* Implement Profiler as specified in #569.

The implmentation is largely inspired by the original `Profiler.swift`
file.

* Add first set of tests.

The test has been largely inspired by the original tests classes.

I have a commented test taht fails. After trying to debug for a while, I
suspect maybe an issue inside GroupProcedure or the original
implementation.

* Apply requested changes.

Perform changes as requested.

* Adds public initialiser to HTTPRequirement (#586)

Declaring a constructor for the `HTTPRequirement` allows the
construction of the struct without any issue.

* Removes GroupProcedureObserver protocol (#583)

Instead ProcedureObserver takes over this responsibility.

* [OPR-574]: Cleans up white space & style for consistency

* [OPR-574]: Uncomments failing test

* [OPR-574]: Adds new API to ProcedureObserver protocol

* [OPR-574]: Removes temporary print statements

* [OPR-574]: Refactors to support willAdd & didAdd observer callbacks.

* [OPR-574]: Removes commented out line.

* [OPR-574]: Removes group observers.

* [OPR-574]: Removes extraneous logging in some tests

* [OPR-574]: Makes add(observer:) open for overriding

* [OPR-574]: Adds some documentation comments to public interfaces

* Supports Arbitrary mutual exclusion category names (#587)

Fixes #580.

* [OPR-580]: Supports arbitrary mutual exclusion category names

* [OPR-580]: Fixes default category for AuthorizedFor

* Adds NetworkReachableProcedure (#563)

* [OPR-563]: Adds Reachability functionality

* [OPR-563]: Adds additional files for testing support

* [OPR-563]: Adds tests for Reachability

* [OPR-563]: Adds basis of NetworkReachableProcedure

* [OPR-563]: Adds simple network reachability procedure tests

* [OPR-563]: Fixes issue with Protector write being synchronous.

* [OPR-563]: Refactors DeviceReachability slightly

* [OPR-563]: Changes Protector behavior back to be non-blocking

* [OPR-563]: Fixes Reachability.Device

* [OPR-563]: Adds NetworkProcedure and ProcedureKitNetworkError

* [OPR-563]: Fixes for network error tests

* [OPR-563]: Adds remaining tests for Reachable procedure

* [OPR-563]: Removes unnecessary logging

* Refactors produce API (#588)

* Add failing test

* Test tweaks

* Changes to Procedure.produce(operation:) handling

Fixes failing test case, and simplifies execution flow.
Changes `willEnqueue()` to `willEnqueue(on: ProcedureQueue)`.
`func produce(operation: Operation)` now throws.

* Ported additional test case from Operations 3.x.

* swiftlint tweak

* Fixed mobile tests.

* Adds missing equality cases for ProcedureKitError.Context (#591)

Fixes #589

* Supports merging collections of ResultInjection Procedures (#593)

* [OPR-593]: Adds gather and reduce APIs

* [OPR-593]: Removes the rethrows

While the nextPartialResult closure can throw, this error is not re-thrown. Instead, because this block is executed after the receiver’s procedures have all finished, the error means that the `ResultProcedure` will finish with an error.

* [OPR-593]: Adds test case for throwing closure

* [OPR-593]: Refactors gather() so that it is a specialization of new flatMap API

* Improves how stress tests are run in CI (#594)

* [OPR-594]: Updates pipeline queues

* [OPR-594]: Fixes yaml

* [OPR-594]: Disables Thread Sanitizer for Stress Tests

* [OPR-594]: Uses Release configuration for stress tests

* Fix StressTestCase Batch counters thread-safety (#555) (#596)

* Fixes public access levels for CKProcedure (#599)

* Fixes some RepeatProcedure thread-safety issues (#597)

Fix issues identified by an audit and Thread Sanitizer

* Fixes Procedure & Support thread-safety (#598)

* Change Protector.write() to be synchronous (and optionally return a value from the block)

Thread Sanitizer identified a data race caused by the combination of
the prior asynchronous `write()` and deinitialization.

* Explicitly `import Dispatch` in Support.swift

Fixes an occasional Xcode warning display glitch.

* Fix Protector.read() to no longer require an `escaping` block

* Adds back `Protector.write(_:completion:)`

Although, like the new write(_:) method, this is now synchronous.

* Wrap all properties of Procedure in a Protector to ensure thread-safety

`errors`, `observers`, `directDependencies`, `conditions` (and
associated methods) are now thread-safe

* Fix comment formatting

* Removes @testable import (#600)

Exposes NSLock and NSRecursiveLock extensions

* Add RepeatProcedure cancellation stress test (#602)

* Adds more GroupProcedure test coverage (#603)

* Additional / improved GroupProcedure test cases

* Remove unused private setter

* Refactors of Result Injection APIs (#601)

* [OPR-601]: Renamed PendingResult to PendingProfileResult

* [OPR-601]: Adds protocols for Input & Output

* [OPR-601]: Refactors for InputProcedure & OutputProcedure

* [OPR-601]: Refactors ReduceProcedure as a TransformProcedure subclass

* [OPR-601]: Refactoring for InputProcedure & OutputProcedure

* [OPR-601]: Refactoring Condition to use Result<Bool>

* [OPR-601]: Refactors ProcedureKitNetwork result injection

* [OPR-601]: Refactors Location for result injection

* [OPR-601]: Removes ResultInjection.swift

* [OPR-601]: Removes left over properties

* [OPR-601]: Tidies up ResultProcedure & TransformProcedure

* [OPR-601]: Adds finish(withResult:) API

* [OPR-601]: Refactors to use finish(withResult:)

* [OPR-601]: Renames HTTPRequirement & HTTPResult

* Renames Result to ProcedureResult (#605)

* [OPR-605]: Renames Result to ProcedureResult

Just to help with any interop issues with antitypical/Result

* [OPR-605]: Renames Result to ProcedureResult

* Adds AsyncBlockProcedure  (#606)

* [OPR-606]: Adds AsyncBlockProcedure

As a specialization of AsyncResultProcedure

* [OPR-606]: Moves async block tests into same file

* [OPR-606]: Adds AsyncTransformProcedure

* Adds @escaping marker to the FinishingBlock (#607)

* Fixes NetworkActivityController internal timer (#608)

* NetworkActivityController's delayed hide should occur on the queue

Fixes data race.

* Remove outdated test

* NetworkDataProcedure, NetworkDownloadProcedure, NetworkUploadProcedure thread-safety (#609)

* Adds NetworkProcedure (#561)

* [OPR-561]: Refactoring ResilientNetworkProcedure

- Supports request timeout
- Adds HTTPStatusCode where we only even consider retrying client or server errors.
- Adds some initial tests

* [OPR-561]: Refactors NetworkResilience

* [OPR-561]: Refactor to unify reachable & resilience network procedures

* [OPR-561]: Adds resilience error handling support

This is so that even if the network request “succeeds” but results in say, a server error, we will still trigger retries.

* [OPR-561]: Fixes typos

* Add missing imports to make Xcode happier (#611)

* Add explicit imports to the top of ProcedureKit files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitCloud files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitMobile files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitLocation files
This makes Xcode happier.

* Fixes BackgroundObserver data race (#614)

* Makes NetworkObserver cross-platform (#613)

* NetworkObserver and NetworkActivityController cross-platform work

On all platforms, the following initializers are available:
`NetworkObserver.init(controller: NetworkActivityController)`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0,
indicator: NetworkActivityIndicatorProtocol)`

To implement your own network activity indicator display, conform to
`NetworkActivityIndicatorProtocol`. NetworkActivityController ensures
that all accesses of the indicator’s `networkActivityIndicatorVisible`
property are serialized on the main queue.

On iOS (but *not* in application extensions), the following convenience
initializers are available that utilize `UIApplication.shared` to
display/hide the network activity indicator in the status bar:
`NetworkObserver.init()`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0)`
`NetworkActivityController.shared`

* [OPR-612]: Moves NetworkObserver into Network framework

* [OPR-612]: Moves NetworkObserver into ProcedureKit

Keeps iOS non-extension related elements in ProcedureKitMobile

* Add documentation

* Fixes BackgroundObserver on iOS 8.x (#615)

To support iOS < 9.0 and macOS < 10.11, NotificationCenter observers
**must** be properly removed, or a crash may result.

* Fixes DelayProcedure thread-safety (#616)

* Fixes to Location related procedures (#619)

* Capability.Location should set its registrar's delegate to nil on deinit.

CLLocationManager’s delegate is `unowned(unsafe)`, and we must ensure
it is set to nil before the object goes away. The only strong reference
to the delegate that Capability.Location sets is stored within
Capability.Location.

* LocationCapabilityTests tweaks

Explicitly set the test CLLocationManager’s `delegate` back to nil.
Explicitly wait on `capability.requestAuthorization` to fulfill an
expectation.

* ReverseGeocodeProcedureTests tweaks

* Fix an occasional crash running the Location tests

It seems there may be an edge case in CoreLocation triggered when
creating (and releasing) lots of CLLocationManager instances (as
previously happened when each test, using its own
TestableLocationServicesRegistrar, created a “fake” CLLocationManager).

Change `TestableLocationServicesRegistrar`’s “fake” CLLocationManager
(which is only used to populate a parameter in the delegate callbacks)
to a static class variable.

* Compiles out SystemConfiguration related stuff from watchOS (#621)

* Adds an All subspec (#623)

* Adds missing imports in TestingProcedureKit (#625)

Noticed this issue after doing some integration testing via CocoaPods

* Network*Procedure tweaks (#626)

* Resolve cancellation race condition in Network*Procedure

Must check `!isCancelled` inside the `stateLock`, or it is possible for
a
`NetworkDataProcedure`/`NetworkDownloadProcedure`/`NetworkUploadProcedur
e` that is cancelled after the `execute()` function is called, but
before the acquisition of the `stateLock` inside it, to continue to
create a network task.

* Mark `task` as `private(set)`

The `task` variable should not be set outside of the
`NetworkDataProcedure` / `NetworkDownloadProcedure` /
`NetworkUploadProcedure`.

* Memory leaks fixes highlighted by Visual Memory Debugger (#624)

* TimeoutObserver should capture a weak reference to the procedure

* RetryIterator should not maintain a strong reference to the RetryProcedure

RetryIterator’s RetryFailureInfo (`info`) property is set right before
`addNextOperation()` is called, which calls `next()` on the
RetryIterator (which then uses the RetryFailureInfo).

Ultimately, the RetryFailureInfo contains strong references to the
RetryProcedure. And since the RetryProcedure owns the RetryIterator,
which owns the RetryFailureInfo… We end up with a reference cycle.

As an immediate quick fix, since the RetryFailureInfo is only used in
the call to `addNextOperation()`, set it back to `.none` after the call.

* Add test to catch reference cycles in RetryProcedure

(Fixed by prior commit.)

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Revert "GroupProcedure: ensure that internal queue is emptied on deinit"

This reverts commit f2b7176fc8a96e841c8829f8d3b903633c50e883.

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Procedure: Use an autoreleasepool in `start()` override

Replicate the `NSOperation.start()` autorelease behavior by pushing an
autoreleasepool before calling `main()`, and popping after `main()`
returns.
This is particularly important because we override the default
`start()` and `main()` behavior, and our `main()` calls the Procedure
subclass’s `execute()` (and we need to ensure that `execute()`, which
is running on a background thread, has an autoreleasepool).

* Resolves cancellation race condition in Network*Procedure (#627)

The internal cancel observer should be a DidCancelObserver.

* Adds step to CI for CocoaPod integration (#630)

* [OPR-630]: Adds TryProcedureKit trigger

* [OPR-630]: Sets the correct commit

* [OPR-630]: Lowercase pipeline name

* [OPR-630]: Fixes a pipeline typo

* [OPR-630]: Renames cocoapods branch in TryProcedureKit

* Fixes copy/paste typos (#634)

Fixes #633.

* Supports result injection in NetworkProcedure (#632)

Closes #631. 

* [OPR-32]: Makes NetworkProcedure conform to OutputProcedure

* [OPR-632]: Adds convenience API for injecting payload from network

* [OPR-632]: Adds tests for injectPayload(fromNetwork:)

* Removes the fatal override of waitUntilFinished() (#635)

* Adds UIProcedure & AlertProcedure (#592)

UIProcedure & AlertProcedure

* ProcessProcedure improvements & thread-safety (#639)

* Move ProcessProcedureTests to the "Mac Tests" group

* ProcessProcedure thread-safety

`NSTask`/`Process` is listed as a Thread-…
danthorpe added a commit that referenced this pull request Mar 29, 2017
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* Adds AnyProcedure (#516)

* [OPR-516]: Removes import foundation

This is done by the prefix header

* [OPR-516]: Adds AnyProcedure

* [OPR-516]: Uses the correct underlying queue throughout AnyProcedure

* Fixes regression of failing release build (#518)

* Renames AuthorizationStatusProtocol to AuthorizationStatus (#519)

* Renames capability reated procedures (#520)

* Renames attach(condition: Condition) to add (#521)

* Adds Capability.CloudKit (#523)

* [OPR-523]: Adds Capability.CloudKit

* [OPR-523]: Enables CI builds for CloudKit stuff on iOS and tvOS

* Adds ProcedureKitNetwork framework (#524)

* [OPR-524]: Adds ProcedureKitNetwork framework

* [OPR-524]: Adds Network to CI jobs

* [OPR-524]: Renames Stress Tests job

* [OPR-524]: Shares the network scheme

* [OPR-524]: Imports Foundation instead of Cocoa

* [OPR-524]: Forces Stress Tests onto a non-simulator agent

* Adds NetworkDataProcedure (#525)

* [OPR-525]: Adds NetworkDataProcedure

* [OPR-525]: Fixes up some unit tests

* [OPR-525]: Adds missing test coverage

* Moves TestableNetwork into TestingProcedureKit framework (#526)

* Refactors injectDependency API to be an extension on ProcedureProtocol instead. (#527)

* Adds transform block result injection API (#528)

* [OPR-528]: Refactors result injection

Uses an intermediatory injectResult(from: via:) API, which allows the caller to provide a throwing block to transform the result into the requirement.

* [OPR-528]: Removes unneeded return

* [OPR-528]: Fixes error in ProcedureKitLocation

* Adds default empty implementations some queue delegate methods (#531)

Only added the will-do-something ones.

Fixes #530

* Adds space in the repo for presentations  (#533)

* [OPR-533]: Adds CocoaHeads Stockholm talk

Contact @danthorpe if you want the original Keynote file.

* [OPR-533]: Adds Sky-UK iOS Community Talk

* [OPR-533]: Adds a presentations README

* Disables the log for AnyProcedure (#534)

* Fixes bug where GroupProcedure collects errors from children after its been cancelled (#532)

* [OPR-532]: Adds failing test

* [OPR-532]: Checks cancelled state of the group

We can exit this delegate callback early if the group has already been cancelled.

* [OPR-532]: Removes default implementation of willFinish

It seems that adding default implementations here causes some odd behaviour / intermittent crash where this is overwritten in the QueueDelegate.

* [OPR-532]: Fixes a unit test which is now mis-counting errors.

* Adds .then { } API (#536)

* [OPR-176]: Adds then extension on Operation

* [OPR-176]: Implements .then { } API

* [OPR-176]: Adds enqueue method to a collection of Operations

* [OPR-176]: Fixes header docs

* Removes default argument for session in NetworkDataProcedure (#538)

* Tweaks the cancel block procedure stress tests (#539)

There might be an underlying issue. As normally a batch of 10_000 finishing in ~ 5 seconds. But sometimes fails because it times out, meaning that an expectation is not getting fulfilled.

* Moves ProcedureKit imports to umbrella headers (#540)

* [OPR-540]: Putting the appropriate imports into umbrella headers

* [OPR-540]: Fixing issues with importing ProcedureKit into TestingProcedureKit

* Updates ProcedureKit podspec with subspecs (#508)

* [OPR-508]: Lints podspec without an warnings or errors.

* [OPR-508]: Fixes errors running tests

* Adds ResilientNetworkProcedure  (#537)

* [OPR-537] Adds ResilientNetworkProcedure

* [OPR-537]: Updates retry request with error code

* [OPR-537]: Adds edge case for ResilientNetworkProcedure

In some situations, the HTTP status code might well require (depending on the behaviour) a retry.

* [OPR-537]: Fixes simple unit tests

* Refactor ResultInjection to use PendingValue enum (#541)

* [OPR-541]: Refactors ResultInjectionProtocol to use PendingValue enum

* [OPR-541]: Renames ResultInjectionProtocol to ResultInjection

* Fixes BlockProcedure stress tests (#544)

* [OPR-544]: Fix test__cancel_block_procedure() failures

It was possible for the testing BlockProcedure to finish prior to the
`block.cancel()` call, which would result in some of the
BlockProcedures never cancelling (as they had finished first), and
a failing test.
Fixed by using a semaphore inside the BlockProcedure’s block.
Additionally, the test now waits for all BlockProcedures to cancel
*and* finish.

* [OPR-544]: Added a new stress test for BlockProcedure cancelling & finishing behavior (allowing for possible races between cancelling and finishing)

* Fixes ExclusivityManager synchronization bug (#545)

Fixes #543 

The ExclusivityManager was using `DispatchQueue.initiated`, which
returns a global **concurrent** queue, however its internals are
dependent upon **serial** execution of add/remove.
Modified to use a serial queue.

* Adds ResultProcedure and overloads injectResult(from:) (#546)

* Adds HTTPResult<Payload> (#547)

* Fix test crashes caused by QueueTestDelegate (#549)

QueueTestDelegate was not thread-safe. This could result in crashes running random tests.
Fixed by making QueueTestDelegate’s methods thread-safe.

* Adds ProcedureKitTestCase wait function that takes an array (#552)

* Adds TestingProcedureKit podspec (#553)

* Adds Mutual Exclusivity concurrency testing (#550)

* Add ConcurrencyTestCase

Exposes functionality to test operation concurrency.

* Add Mutual Exclusivity concurrency tests

* Refactored ConcurrencyTestCase

* Refactored ConcurrencyTestCase

* Adds didExecuteObserver (#554)

* [OPR-554]: Adds code with failing test

* [OPR-554]: Calls didExecuteObservers

* [OPR-554]: Fixes a typo

* [OPR-554]: Adds some documentation to the DidExecuteObserver

* Fixes mistake in Fastfile (#557)

* [OPR-557]: Fixes error in Fastfile

* [OPR-557]: Removes duplicate scan

I remember now, as part of location, we used to build Mobile too - because there was a dependency on iOS. But this has since been removed.

* Fixes release configuration issues with Xcode 8.1 (#559)

Fixes #548 

* [OPR-548]: Fixes issue with Xcode 8.1 release configuration

* [OPR-548]: Fixes some SwiftLint warnings.

* [OPR-548]: Fixes Xcode project warnings in Xcode 8.1

* Adds GroupProcedure concurrency tests (#556)

* Add GroupConcurrencyTestCase

* Add GroupProcedure.maxConcurrentOperationCount tests

* Fixes registrar typo (#562)

* Adds NetworkDownloadProcedure. (#565)

The implementation for class and test is largely inspired by
`NetworkDataProcedure` class.

* Adds NetworkUploadProcedure. (#567)

* Add NetworkUploadProcedure.

The implementation class and test has been largely inspired by
`NetworkDataProcedure`.

The requirement type is currently a pending value of a tuple.
Maybe would it make more sense to create a dedicated struct to add more
clarity in the case of dependencies injection ?

* Use an `HTTPRequirement` struct for requirement.

As discussed, an `HTTPRequirement` struct is used instead of a tuple.

* Fixes Condition to support ResultInjection (#566)

* [OPR-566]: Replaces Condition result with PendingValue<ConditionResult>

* [OPR-566]: Refactors how conditions are evaluated

This fixes a existing issue where the ConditionEvaluation enum was basically just like ConditonResult, except that it could hold an array of errors.

This has been resolved by using an internal error type `ProcedureKitError.FailedConditions` to collect multiple errors from failed conditons, so that we can reduce a sequence of `ConditionResult`s into a single one.

* [OPR-566]: Explicitly adds a Result typealias

* [OPR-566]: Fixes error where cancelled conditions would throw a fatal error.

* [OPR-566]: Removes verbose log

* Adds ProcessProcedure. (#570)

* Add ProcessProcedure.

The class has been largely inspired by the original `TaskOperation`.
Refers to #568.

* Apply requested changes.

Correctly implement `Equatable` for sub-error enum.
Use camel case for the enum.
Fix closure self semantics.

* Calls TestableReverseGeocoder completionHandler on the main queue (#572)

* Improves performance of adding observers

* Procedure.add(observer:) performance tweak

Append directly to the protected observers array.

* Fix swiftlint `variable_name` warning

* Makes ProcedureQueue.add(operation: Operation) method open (#578)

* Fixes NetworkObserver thread-safety (#576) (#577)

* Fix NetworkObserver thread-safety

By fixing NetworkActivityController `start()`/`stop()` thread-safety.
(And making private methods/variables private.)

* NetworkObserver test fixes

* Reduce test delay

* Additional GroupProcedure tests (#579)

* Adds CloudKitProcedure (#542)

* [OPR-542]: Adds shell of CloudKit files

* [OPR-542]: Adds extensions for CKOperation

* [OPR-542]: Adds extensions for CKDatabaseOperation

* [OPR-542]: Adds extensions for CKAcceptSharesOperation

* [OPR-542]: Adds extensions for CKDiscoverAllContactsOperation

* [OPR-542]: Adds extensions for CKDiscoverAllUserIdentifiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserInfosOperation

* [OPR-542]: Adds extensions for CKFetchDatabaseChanges

* [OPR-542]: Adds extensions for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds extensions for CKFetchRecordChangesOperation

* [OPR-542]: Moves the interface into the extension files

* [OPR-542]: Fixes dispatchQueue

* [OPR-542]: Adds extensions to CKFetchRecordsOperation

* [OPR-542]: Adds extensions for CKFetchRecordZoneChangesOperation

* [OPR-542]: Removes unnecessary public properties

* [OPR-542]: Adds extensions for CKFetchRecordZonesOperation

* [OPR-542]: Adds extensions for CKFetchShareMetadataOperation

* [OPR-542]: Adds extensions for CKFetchShareParticipantsOperation

* [OPR-542]: Adds extensions for CKFetchSubscriptionsOperation

* [OPR-542]: Adds extensions for CKMarkNotificationsReadOperation

* [OPR-542]: Adds extensions for CKModifyBadgeOperation

* [OPR-542]: Adds extensions for CKModifyRecordsOperation

* [OPR-542]: Adds extensions for CKModifyRecordZonesOperation

* [OPR-542]: Adds extensions for CKModifySubscriptionsOperation

* [OPR-542]: Adds extensions for CKQueryOperation

* [OPR-542]: Adds missing APIs for error handlers

* [OPR-542]: Adds testable CK operation classes

* [OPR-542]: Adds tests for CKOperation, CKDatabaseOperation and CKAcceptSharesOperation

* [OPR-542]: Removes missing test cases from tvOS

* Small typo fix

* Adds tests for CKDiscoverAllContactsOperation

* Adds tests for CKDiscoverAllUserIdentitiesOperation

* Adds tests for CKDiscoverUserIdentitiesOperation

* Adds tests for CKDiscoverUserInfosOperation

* [OPR-542]: Adds tests for CKFetchAllChanges protocol

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordsOperation

* [OPR-542]: Added missing `recordZoneFetchCompletionBlock` for CKFetchRecordZoneChangesOperationProtocol extensions

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Minor typo fix

To follow the original API naming, change
`setMarkNotificationReadCompletionBlock` to
`setMarkNotificationsReadCompletionBlock`.

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds tests for CKModifySubscriptionsOperation

* [OPR-542]: Adds tests for CKQueryOperation

* [OPR-542]: Fixes whitespace in test cases

* [OPR-542]: Adds CloudKitProcedure<CKAcceptSharesOperation> tests

* [OPR-542]: Fixes tests on tvOS. Again.

* [OPR-542]: Adds tests for CKDiscoverAllContactsOperation

* [OPR-542]: Adds tests for CKDiscoverAllUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserInfosOperations

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Unifies testing of common properites

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds test for CKFetchRecordsOperation

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds test for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Fixes inconsistently named tests

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds test for CKModifySubscriptionsOperation

* [OPR-542]: Adds test for CKQueryOperation

* [OPR-542]: Adds tests which trigger default retry behavior

* [OPR-542]: Adds tests for set/get all errors handlers

* [OPR-542]: Adds tests for custom error handlers

* Adds Profiler (#573)

* Implement Profiler as specified in #569.

The implmentation is largely inspired by the original `Profiler.swift`
file.

* Add first set of tests.

The test has been largely inspired by the original tests classes.

I have a commented test taht fails. After trying to debug for a while, I
suspect maybe an issue inside GroupProcedure or the original
implementation.

* Apply requested changes.

Perform changes as requested.

* Adds public initialiser to HTTPRequirement (#586)

Declaring a constructor for the `HTTPRequirement` allows the
construction of the struct without any issue.

* Removes GroupProcedureObserver protocol (#583)

Instead ProcedureObserver takes over this responsibility.

* [OPR-574]: Cleans up white space & style for consistency

* [OPR-574]: Uncomments failing test

* [OPR-574]: Adds new API to ProcedureObserver protocol

* [OPR-574]: Removes temporary print statements

* [OPR-574]: Refactors to support willAdd & didAdd observer callbacks.

* [OPR-574]: Removes commented out line.

* [OPR-574]: Removes group observers.

* [OPR-574]: Removes extraneous logging in some tests

* [OPR-574]: Makes add(observer:) open for overriding

* [OPR-574]: Adds some documentation comments to public interfaces

* Supports Arbitrary mutual exclusion category names (#587)

Fixes #580.

* [OPR-580]: Supports arbitrary mutual exclusion category names

* [OPR-580]: Fixes default category for AuthorizedFor

* Adds NetworkReachableProcedure (#563)

* [OPR-563]: Adds Reachability functionality

* [OPR-563]: Adds additional files for testing support

* [OPR-563]: Adds tests for Reachability

* [OPR-563]: Adds basis of NetworkReachableProcedure

* [OPR-563]: Adds simple network reachability procedure tests

* [OPR-563]: Fixes issue with Protector write being synchronous.

* [OPR-563]: Refactors DeviceReachability slightly

* [OPR-563]: Changes Protector behavior back to be non-blocking

* [OPR-563]: Fixes Reachability.Device

* [OPR-563]: Adds NetworkProcedure and ProcedureKitNetworkError

* [OPR-563]: Fixes for network error tests

* [OPR-563]: Adds remaining tests for Reachable procedure

* [OPR-563]: Removes unnecessary logging

* Refactors produce API (#588)

* Add failing test

* Test tweaks

* Changes to Procedure.produce(operation:) handling

Fixes failing test case, and simplifies execution flow.
Changes `willEnqueue()` to `willEnqueue(on: ProcedureQueue)`.
`func produce(operation: Operation)` now throws.

* Ported additional test case from Operations 3.x.

* swiftlint tweak

* Fixed mobile tests.

* Adds missing equality cases for ProcedureKitError.Context (#591)

Fixes #589

* Supports merging collections of ResultInjection Procedures (#593)

* [OPR-593]: Adds gather and reduce APIs

* [OPR-593]: Removes the rethrows

While the nextPartialResult closure can throw, this error is not re-thrown. Instead, because this block is executed after the receiver’s procedures have all finished, the error means that the `ResultProcedure` will finish with an error.

* [OPR-593]: Adds test case for throwing closure

* [OPR-593]: Refactors gather() so that it is a specialization of new flatMap API

* Improves how stress tests are run in CI (#594)

* [OPR-594]: Updates pipeline queues

* [OPR-594]: Fixes yaml

* [OPR-594]: Disables Thread Sanitizer for Stress Tests

* [OPR-594]: Uses Release configuration for stress tests

* Fix StressTestCase Batch counters thread-safety (#555) (#596)

* Fixes public access levels for CKProcedure (#599)

* Fixes some RepeatProcedure thread-safety issues (#597)

Fix issues identified by an audit and Thread Sanitizer

* Fixes Procedure & Support thread-safety (#598)

* Change Protector.write() to be synchronous (and optionally return a value from the block)

Thread Sanitizer identified a data race caused by the combination of
the prior asynchronous `write()` and deinitialization.

* Explicitly `import Dispatch` in Support.swift

Fixes an occasional Xcode warning display glitch.

* Fix Protector.read() to no longer require an `escaping` block

* Adds back `Protector.write(_:completion:)`

Although, like the new write(_:) method, this is now synchronous.

* Wrap all properties of Procedure in a Protector to ensure thread-safety

`errors`, `observers`, `directDependencies`, `conditions` (and
associated methods) are now thread-safe

* Fix comment formatting

* Removes @testable import (#600)

Exposes NSLock and NSRecursiveLock extensions

* Add RepeatProcedure cancellation stress test (#602)

* Adds more GroupProcedure test coverage (#603)

* Additional / improved GroupProcedure test cases

* Remove unused private setter

* Refactors of Result Injection APIs (#601)

* [OPR-601]: Renamed PendingResult to PendingProfileResult

* [OPR-601]: Adds protocols for Input & Output

* [OPR-601]: Refactors for InputProcedure & OutputProcedure

* [OPR-601]: Refactors ReduceProcedure as a TransformProcedure subclass

* [OPR-601]: Refactoring for InputProcedure & OutputProcedure

* [OPR-601]: Refactoring Condition to use Result<Bool>

* [OPR-601]: Refactors ProcedureKitNetwork result injection

* [OPR-601]: Refactors Location for result injection

* [OPR-601]: Removes ResultInjection.swift

* [OPR-601]: Removes left over properties

* [OPR-601]: Tidies up ResultProcedure & TransformProcedure

* [OPR-601]: Adds finish(withResult:) API

* [OPR-601]: Refactors to use finish(withResult:)

* [OPR-601]: Renames HTTPRequirement & HTTPResult

* Renames Result to ProcedureResult (#605)

* [OPR-605]: Renames Result to ProcedureResult

Just to help with any interop issues with antitypical/Result

* [OPR-605]: Renames Result to ProcedureResult

* Adds AsyncBlockProcedure  (#606)

* [OPR-606]: Adds AsyncBlockProcedure

As a specialization of AsyncResultProcedure

* [OPR-606]: Moves async block tests into same file

* [OPR-606]: Adds AsyncTransformProcedure

* Adds @escaping marker to the FinishingBlock (#607)

* Fixes NetworkActivityController internal timer (#608)

* NetworkActivityController's delayed hide should occur on the queue

Fixes data race.

* Remove outdated test

* NetworkDataProcedure, NetworkDownloadProcedure, NetworkUploadProcedure thread-safety (#609)

* Adds NetworkProcedure (#561)

* [OPR-561]: Refactoring ResilientNetworkProcedure

- Supports request timeout
- Adds HTTPStatusCode where we only even consider retrying client or server errors.
- Adds some initial tests

* [OPR-561]: Refactors NetworkResilience

* [OPR-561]: Refactor to unify reachable & resilience network procedures

* [OPR-561]: Adds resilience error handling support

This is so that even if the network request “succeeds” but results in say, a server error, we will still trigger retries.

* [OPR-561]: Fixes typos

* Add missing imports to make Xcode happier (#611)

* Add explicit imports to the top of ProcedureKit files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitCloud files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitMobile files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitLocation files
This makes Xcode happier.

* Fixes BackgroundObserver data race (#614)

* Makes NetworkObserver cross-platform (#613)

* NetworkObserver and NetworkActivityController cross-platform work

On all platforms, the following initializers are available:
`NetworkObserver.init(controller: NetworkActivityController)`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0,
indicator: NetworkActivityIndicatorProtocol)`

To implement your own network activity indicator display, conform to
`NetworkActivityIndicatorProtocol`. NetworkActivityController ensures
that all accesses of the indicator’s `networkActivityIndicatorVisible`
property are serialized on the main queue.

On iOS (but *not* in application extensions), the following convenience
initializers are available that utilize `UIApplication.shared` to
display/hide the network activity indicator in the status bar:
`NetworkObserver.init()`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0)`
`NetworkActivityController.shared`

* [OPR-612]: Moves NetworkObserver into Network framework

* [OPR-612]: Moves NetworkObserver into ProcedureKit

Keeps iOS non-extension related elements in ProcedureKitMobile

* Add documentation

* Fixes BackgroundObserver on iOS 8.x (#615)

To support iOS < 9.0 and macOS < 10.11, NotificationCenter observers
**must** be properly removed, or a crash may result.

* Fixes DelayProcedure thread-safety (#616)

* Fixes to Location related procedures (#619)

* Capability.Location should set its registrar's delegate to nil on deinit.

CLLocationManager’s delegate is `unowned(unsafe)`, and we must ensure
it is set to nil before the object goes away. The only strong reference
to the delegate that Capability.Location sets is stored within
Capability.Location.

* LocationCapabilityTests tweaks

Explicitly set the test CLLocationManager’s `delegate` back to nil.
Explicitly wait on `capability.requestAuthorization` to fulfill an
expectation.

* ReverseGeocodeProcedureTests tweaks

* Fix an occasional crash running the Location tests

It seems there may be an edge case in CoreLocation triggered when
creating (and releasing) lots of CLLocationManager instances (as
previously happened when each test, using its own
TestableLocationServicesRegistrar, created a “fake” CLLocationManager).

Change `TestableLocationServicesRegistrar`’s “fake” CLLocationManager
(which is only used to populate a parameter in the delegate callbacks)
to a static class variable.

* Compiles out SystemConfiguration related stuff from watchOS (#621)

* Adds an All subspec (#623)

* Adds missing imports in TestingProcedureKit (#625)

Noticed this issue after doing some integration testing via CocoaPods

* Network*Procedure tweaks (#626)

* Resolve cancellation race condition in Network*Procedure

Must check `!isCancelled` inside the `stateLock`, or it is possible for
a
`NetworkDataProcedure`/`NetworkDownloadProcedure`/`NetworkUploadProcedur
e` that is cancelled after the `execute()` function is called, but
before the acquisition of the `stateLock` inside it, to continue to
create a network task.

* Mark `task` as `private(set)`

The `task` variable should not be set outside of the
`NetworkDataProcedure` / `NetworkDownloadProcedure` /
`NetworkUploadProcedure`.

* Memory leaks fixes highlighted by Visual Memory Debugger (#624)

* TimeoutObserver should capture a weak reference to the procedure

* RetryIterator should not maintain a strong reference to the RetryProcedure

RetryIterator’s RetryFailureInfo (`info`) property is set right before
`addNextOperation()` is called, which calls `next()` on the
RetryIterator (which then uses the RetryFailureInfo).

Ultimately, the RetryFailureInfo contains strong references to the
RetryProcedure. And since the RetryProcedure owns the RetryIterator,
which owns the RetryFailureInfo… We end up with a reference cycle.

As an immediate quick fix, since the RetryFailureInfo is only used in
the call to `addNextOperation()`, set it back to `.none` after the call.

* Add test to catch reference cycles in RetryProcedure

(Fixed by prior commit.)

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Revert "GroupProcedure: ensure that internal queue is emptied on deinit"

This reverts commit f2b7176fc8a96e841c8829f8d3b903633c50e883.

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Procedure: Use an autoreleasepool in `start()` override

Replicate the `NSOperation.start()` autorelease behavior by pushing an
autoreleasepool before calling `main()`, and popping after `main()`
returns.
This is particularly important because we override the default
`start()` and `main()` behavior, and our `main()` calls the Procedure
subclass’s `execute()` (and we need to ensure that `execute()`, which
is running on a background thread, has an autoreleasepool).

* Resolves cancellation race condition in Network*Procedure (#627)

The internal cancel observer should be a DidCancelObserver.

* Adds step to CI for CocoaPod integration (#630)

* [OPR-630]: Adds TryProcedureKit trigger

* [OPR-630]: Sets the correct commit

* [OPR-630]: Lowercase pipeline name

* [OPR-630]: Fixes a pipeline typo

* [OPR-630]: Renames cocoapods branch in TryProcedureKit

* Fixes copy/paste typos (#634)

Fixes #633.

* Supports result injection in NetworkProcedure (#632)

Closes #631. 

* [OPR-32]: Makes NetworkProcedure conform to OutputProcedure

* [OPR-632]: Adds convenience API for injecting payload from network

* [OPR-632]: Adds tests for injectPayload(fromNetwork:)

* Removes the fatal override of waitUntilFinished() (#635)

* Adds UIProcedure & AlertProcedure (#592)

UIProcedure & AlertProcedure

* ProcessProcedure improvements & thread-safety (#639)

* Move ProcessProcedureTests to the "Mac Tests" group

* ProcessProcedure thread-safety

`NSTask`/`Process` is listed as a Thread-…
danthorpe added a commit that referenced this pull request Apr 8, 2017
* Will Cancel Observer (#293)

* [OPR-293]: Refactors Start & Cancellation observers

* [OPR-293]: Go back to original group cancellation policy

* [OPR-293]: Adds errors to will cancel observer

* [OPR-293]: Avoids overriding cancel

Instead adds a will cancel observer.

* [OPR-293]: Corrects mistake where the queue was not suspended

!!

* [OPR-293]: Makes cancel a final method

This prevents Operation subclasses from overriding cancel. Instead, they should add an observer as appropriate.

WillCancelObserver <- block is executed directly before the operation will change its cancellation state.

DidCancelObserver <- block is executed directly after the operation did change its cancellation state.

Typically, subclasses will want to observe WillCancel to update their own internal state. But consumers will want to observe DidCancel to respond to operations being cancelled.

* [OPR-293]: Adds to new operations to property

Also makes the queue private.

* [OPR-293]: Cancels all operations in the queue.

This will ensure that the finishing operation is also cancelled.

* [OPR-293]: Adds will/did cancel API

* [OPR-293]: Fixes some issues with GroupOperation

One of the issues with adding the operations to the queue in the initializer, is that observers will not get notified.

So, we have to add the initial operations in `execute`. But, if we append to operations in addOperations, that means, we need to filter out any instances which have already been added.

For example, a subclass may well implement execute to first addOperation(myOperation); super.execute() which would cause a crash if we tried adding myOperation twice.

* [OPR-293]: Renames will/didFinish

This is to be consistent with operationWill/operationDidCancel

* Conditions as Operations (#286)

* [OPR-278]: Adds protocols for OperationType

* [OPR-278]: Creates ConditionOperation

With internal types for wrapping OperationCondition, and evaluating groups.

* [OPR-278]: Initial work removing ready override.

* [OPR-278]: Enables previously failing test

* [OPR-278]: Adds missing files to Extension project

* [OPR-278]: Enables previously failing test in iOS scheme too

* [OPR-278]: Increases the batch size.

Also removes the logging.

* [OPR-278]: Fixes scheduling of dependencies.

* [OPR-278]: Further fixes to dependency scheduling.

* [OPR-278]: Removes unnecessary protocols

* [OPR-278]: Removes dependency between evaluator and conditons

This can introduce a deadlock with mutual exclusivity.

* [OPR-278]: Fixes incorrect test with profiler.

* [OPR-278]: Enables all tests on OS X

* [OPR-278]: Enables all tests on iOS

* [OPR-278]: Prevents a retain cycle in ConditionOperation

* [OPR-278]: Adds failing test to clarify mutual exclusivity

* [OPR-278]: Sets mutual exclusion around operation

This was a mistake - it was getting set on the condition.

* [OPR-278]: Fixes mutual exclusivity tests

* [OPR-278]: Sorts out mutual conditions with dependencies

Also, operations which have dependencies, and mutually exclusive conditions which have dependencies.

* [OPR-278]: Clean up the code a bit

* [OPR-278]: Includes indirect dependencies

* [OPR-278]: Starts adding Stress Tests

This is a new test bundle which gets tested as part of the OS X test suite.

* [OPR-278]: Renames ConditionOperation to Condition

It *is* an operation, but I want it to be treated like a Condition with it's own evaluate API

* [OPR-278]: Sets up tests

* [OPR-278]: Renames to mutuallyExclusive

* [OPR-278]: Fixes target reference for Condition.swift

* [OPR-278]: Adds ComposedCondition

This is useful (and uses automatic result injection) for easily getting the result of a previous condition.

* [OPR-278]: Refactors BlockCondition

* [OPR-278]: Refactors NegatedCondition

* [OPR-278]: Initial work on updating framework conditions

- [x] BlockCondition
- [x] TrueCondition
- [x] FalseCondition
- [x] ComposedCondition
- [x] SilentCondition
- [x] NegatedCondition
- [x] MutuallyExclusive
- [x] NoFailedDependenciesCondition

* [OPR-278]: Corrects a mistake with removeDependencies

We we actually just adding?!

* [OPR-278]: Mixes the composed direct dependencies

* [OPR-278]: Updates UserNotificationCondition

to subclass Condition

* [OPR-278]: Fixes some tests for iOS

* [OPR-278]: Refactors AuthorizedFor

* [OPR-278]: Refactors UserConfirmationCondition

* [OPR-278]: Refactors ReachabilityCondition

* [OPR-278]: Refactors AddressBookCondition

* [OPR-278]: Refactors ContactsCondition

* [OPR-278]: Refactors RemoteNotificationCondition

* [OPR-278]: Adds @available annotation.

Still not really sure how to accuractly mark API as deprecated inside a framework.

* [OPR-278]: Adds some tests for conditions

* [OPR-278]: Refactors condition error type

* [OPR-278]: Refactors True False Condition

* [OPR-278]: Cleans up Condition tests

* [OPR-278]: Fixes tests

* Fixes an incorrect Fix-It hint. (#302)

Fixes #299.

* Fixes notice severity logs (#303)

This was done during development and accidentally committed & pushed.

Fixes #300

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* CLLocationAuthorizationStatus bug (#306)

* Fixes bug: CLLocationManager prematurely responds with 'NotDetermined' auth status when asking for permission (#305)

* [OPR-306]: Adds test coverage for location capability

* Improved support for CloudKit Errors (#304)

* [OPR-290]: Adds Error associated type on CKOperationType

At the moment, this is just fulfilled by NSError, however it will allow us to offer specialized error responses depending on the operation.

* [OPR-290]: Updates test cloud kit operation.

* [OPR-290]: Adds missing file to Extension project

* [OPR-290]: Moves CloudKit sources into a folder

* [OPR-290]: Adds errors for Modify Zones & Records

* [OPR-290]: Adds custom error types for all CloudKit Operations

* [OPR-290]: Fixes error handling

Now every CKOperation has it's own bespoke error type.

* [OPR-290]: Tidies up AssociatedErrorType

* [OPR-290]: Fixes issues with AssociatedErrorType

* [OPR-290]: Adds error recovery to BatchedCloudKitOperation

* [OPR-290]: Exposes properties on OPRCKOperation

These are needed to configure operations inside error handlers.

* Removes unnecessary let statement (#310)

* Supports entersReaderIfAvailable configuration in WebpageOperation. (#312)

It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Refactors WebpageOperation to subclass ComposedOperation  (#315)

* Extended WebpageOperation with the ability to configure entersReaderIfAvailable at initialization.
It is possible now to show an SFSafariViewController with entersReaderIfAvailable set to false.

* Fixed a bug in WebpageOperation that that resulted in a retain cycle.

* - Refactored WebpageOperation as ComposedOperation to fix a retain cycle.
- Added Documentation.

* Fixed some typos in WebpageOperationTests.

* Implemented OpenInSafariOperation (#317)

* Implemented OpenInSafariOperation

* Made the displayControllerFrom non optional.

* Refactored OpenInSafariOperation.

* Fixes a bug removing dependencies on Condition (#309)

The issue is that ComposedCondition must remove the dependency on its composed condition too.

* Improves cancellation checks in main() (#319)

* [OPR-287]: Invokes observers in main

main() is called from start, and we already check that the operation is not cancelled. Therefore the check at the start of main is redundant. However, we don't check after the observers have been executed that the operation is cancelled.

* [OPR-287]: SwiftLint fixes.

* Exposes LogSeverity enum to Objective-C (#324)

* Remove Reachability from CloudKitOperation (#327)

* Ignore DS_Store

* Rip out reachability from CloudKitOperation

* [OPR-327]: Adds trailing closure syntax

* [OPR-327]: Adds TimeoutObserver

* [OPR-327]: Adds tests for timeout observer

* Override NSOperationQueue's mainQueue() (#330)

* Override NSOperationQueue's mainQueue() to return the main queue as an OperationQueue

* set maxConcurrentOperationCount to 1

* Adds missing functionality of UIAlertController to AlertOperation (#334)

* Added missing functionality of UIAlertController to AlertOperation.

* Annotated new functionality as public.

* Added test cases for new functionality.

* Made alert property of AlertOperation private.

* SwiftLint corrections.

* Added a test for preferredAction and fixed a but related to it.

* Made UserIntent enum objc accessbile (#341)

* Fixed network observer flickering (#338)

Added tests for multiple operations having network observer

* Supports error recovery in GroupOperation (#326)

* [OPR-326]: Adds Errors subtype in Operation

* [OPR-326]: Refactors GroupOperation willFinish API

* Revert "[OPR-326]: Adds Errors subtype in Operation"

This reverts commit 759f2ef3643cafbbda3544185234b8adeec474ef.

* [OPR-326]: WIP on group operation errors

* [OPR-326]: Fixes issues with retry operation tests

This is still not quite right.

* [OPR-326]: Allows RetryOperation to fully recover from errors

* [OPR-326]: Fixes issue with tests

* [OPR-326]: Tweaks ProfilerTest case

* [OPR-326]: Refactors ComposedOperation to just subclass GroupOperation

* [OPR-326]: Changes behaviour when a group produces an operation

* [OPR-326]: Logs when a GroupOperation successfully recovers from errors

* [OPR-326]: Logs when the next operation will be added

* [OPR-326]: Adds an immediate WaitStrategy

* [OPR-326]: Adds the operation to the log when attempting recovery

* [OPR-326]: Removes unneeded handling of child errors

* [OPR-326]: Allows the WaitStrategy to be defined at init

* [OPR-326]: Changes to support ComposedOperation

* [OPR-326]: Speeds up CloudKit tests with .Immediate wait strategy

* [OPR-326]: WIP on GroupOperation errors

* [OPR-326]: Fixes a bug where operation would not retry

In the case where there is a default handler, but no custom one set for the same error.

* [OPR-326]: Renames internal methods to be more Swifty

* [OPR-326]: Fixes errors - whoops.

* Always create CLLocationManager on the main queue (#321)

* [OPR-321]: Creates CLLocationManager on the main thread

Also makes it thread safe.

* [OPR-321]: Refactors capability to use guard & early exit.

* [OPR-321]: Creates CLLocationManager lazily on the main thread

Refactors UserLocationOperation to not use generic at the same time

* [OPR-321]: Fixes deadlock in creating CLLocationManager

* [OPR-321]: Refactors location operations for early exit

* [OPR-321]: Removes use of NSThread to check for main queue

* [OPR-321]: Fixes a mistake with the merge

* RepeatedOperation allows for configuration block to be reset by the payload (#348)

* [OPR-332]: Adds support for RetryOperation to provide a configuration block

* [OPR-332]: Removes commented out code

* [OPR-332]: Adds test to check that configure block is replaced

* Turns on Whole Module Optimization (#350)

Fixes #349

* Exposes the UIAlert for customization. (#351)

This also fixes a bug where it wasn't possible to set a barButtonItem on an ActionSheet while presenting as a popover.

* Fixes OperationQueue.delegate crash (SR-192) (#353)

* Add failing test

test__SR_192_OperationQueue_delegate_weak_var_thread_safety:
Tests race condition (and crash) involving OperationQueue’s weak
delegate var.

* Fix for OperationQueue.delegate crash (SR-192)

The underlying error is in Swift < 3.0, with concurrent reads of weak
properties.
See: https://bugs.swift.org/browse/SR-192

This change wraps the public delegate property with an NSLock. It also
sets it to nil first-thing in deinit to safely get rid of it.

* Simplistic support for CKLimitExceeded error handling (#294)

* [OPR-294]: Initial work adding built in support for CKLimitExceeded

* [OPR-294]: Rewrite with support for nil response

* [OPR-294]: Adds support for adding error handlers in bulk

* [OPR-294]: Fixes some comments

* [OPR-294]: Moves error handling to CloudKitError

* [OPR-294]: Adds BatchProcessErrorType

This is only needed for CKMarkNotificationsOperation

* [OPR-294]: Renames error protocols

* [OPR-294]: Adds support for batch processing

* [OPR-294]: Adds & Refactors for tests

* [OPR-294]: Minor tweaks

* [OPR-294]: Further tweaks

* [OPR-294]: Fixes error in bisect

* [OPR-294]: Adds API to replace the configure block outright

* [OPR-294]: Fixes failing tests

* [OPR-294]: Refactors stress tests condition

* Adds TaskOperation (#355)

* [OPR-313]: Adds TaskOperation

* [OPR-313]: Adds more test coverage

* [OPR-313]: Adds header documentation

* Vastly improves thread safety in Operations (#358)

* FIX: GroupOperation.operations contains the initial operations twice after beginning to execute.

Cause:
`GroupOperation.execute()` calls
`GroupOperation.addOperations(operations)`,
which then re-adds the operations back to the operations array.

Solution:
Added a private **`_addOperations()`** method to `GroupOperation` with
an additional flag to override this behavior - used in
`GroupOperation.execute()`.

`addOperations()` now calls this private implementation method.

* Operation.cancel(), Operation.finish() thread-safety

- `Operation.cancel()` now acquires the stateLock.
- `Operation.finish()` now acquires the stateLock.
- `stateLock` is now NSRecursiveLock().
- var `Operation.cancelled` is thread-safe.
- var `Operation.errors` is thread-safe.
- Explicitly send KVO notifications on NSOperation keyPaths
at the right times, avoiding lots of unnecessary notifications.
- Removed “State” KVO notifications. (Previously used to
trigger NSOperation isExecuting/isFinished notifications,
which are now triggered explicitly.)
- Added missing operationWillFinish() call to finish().
- operationDidFinish() now happens after the state has been
set to .Finished.
- `Operation.cancelWithError(errors)` now asserts if it’s
called while the Operation is finishing or finished.

* Operation.main() thread-safety, Operation.disableAutomaticFinishing

- `Operation.main()` acquires the stateLock when appropriate.
- `Operation.main()` manually sends the isExecuting NSOperation KVO
notifications when setting executing state.
- Added ability to disable Operation’s automatic calling of finish(),
with `init(disableAutomaticFinishing: Bool)`. (Defaults to existing
behavior - i.e. false.)

* GroupOperation improvements (finish and thread-safety)

- GroupOperation should only finish() after its children have finished.
- `GroupOperation._addOperations()` acquires the stateLock.
- `GroupOperation._addOperations()` cancels new child operations if the
GroupOperation is cancelled.

* RepeatedOperation.addNextOperation() must check cancelled

- RepeatedOperation.addNextOperation() now checks cancelled status.

* Added new cancellation-related tests

* Added new GroupOperation tests

* Added Operation KVO notification tests (for NSOperation keyPaths)

* Fixed spurious commit

* Handle more possible cases in Operation.main()

- Check that the Operation is not already executing.
- Check that the Operation has not been finished by a WillExecute
observer (either directly or as a side-effect of something else). Added
a test case that demonstrates this possibility.

* Add missing super.init() calls

* More GroupOperation cancelling fixes

- Changed the internal WillCancelObserver to a DidCancelObserver to
ensure that the cancelled state has been set prior to cancelling child
operations. (This ensures that side-effects of propagating cancellation
to child operations - like RepeatedOperation attempting to add the next
operation - can safely check the cancelled status.)

* GroupOperation should not call queue.cancelAllOperations()

Calling queue.cancelAllOperations() also cancels the
finishingOperation, which skips properly waiting until all other child
operations are finished.
Fixed test.

* Added willProduceOperation method to OperationQueueDelegate, fix GroupOperation handling of child-produced operations

Informational method only.
This enables GroupOperation to add child-produced operations to its
internal operations array, and thus cancel them when the GroupOperation
is cancelled.
Added tests.

* GroupOperation should ignore queue delegate calls from other queues

Added missing guard at the top of the queue delegate methods in
GroupOperation.
Added test to illustrate simple failure case this change covers.

* Refactor lock usage in Operation.finish() and .cancel()

- Refactor lock usage to hold the stateLock only when necessary or
manipulating internal state, and *not* when sending KVO notifications
or notifying observers.
- Improvements and fixes to KVO Notification Tests.

* Further refactor lock usage in Operation (.execute())

- Refactor lock usage in `Operation.execute()` to hold the stateLock
only when necessary or manipulating internal state, and *not* when
sending KVO notifications or notifying observers.

* Add a number of new StressTests that previously failed/crashed

New tests have support for a `batches` parameter.

* Initial fix for Logging-related crashes (thread-safety issues)

- `Operation._log` must not be a lazy var.
From the Swift book:
> If a property marked with the lazy modifier is accessed by multiple
threads simultaneously and the property has not yet been initialized,
there is no guarantee that the property will be initialized only once.
For more: https://bugs.swift.org/browse/SR-1042
- `Operation.log` must be thread-safe.
Initial fix involves capturing a copy of the logging context (settings
+ operationName) at the time of access of `Operation.log`, returning
that captured context as a LoggerType, and surrounding access of .log
with a Read/Write lock.
- LogManager properties must be thread-safe.

* Refactor lock usage in GroupOperation

- var `GroupOperation.operations` is now thread-safe.
- GroupOperation now utilizes a private CanFinishOperation to safely
transition to executing the finishingOperation. (See code & comments.)
- GroupOperation now has its own lock that is used sparingly to protect
finishing state.
- `GroupOperation._addOperation()` now utilizes the groupFinishLock.

* Minor tweaks

- `Operation.stateLock` should remain private.

* SwiftLint clean-up

* Refactor lock usage in GroupOperation

- Refactor lock usage to hold the groupFinishLock only when necessary
or manipulating internal state, and *not* when sending KVO
notifications, notifying observers, or changing additionalOperations
state (which might send KVO notifications or notify observers).

* Clean-up

- Remove asserts from `Operation.cancelWithErrors()`. Operation
cancellation methods should be safe to call at any time without
asserting.
- Other minor tweaks.

* Clean-up

- Moved NSOperationKeyPaths to extension NSOperation.KeyPath enum.

* Clean-up

* Clean-up

- Remove unneeded `self.`

* Clean-up

* Clarify docs & re-formatting

* Add new inits to Queue (NSQualityOfService and qos_class_t)

Per code review.

* Clean-up of GroupOperation

* Make Operation.cancel() final (#359)

Per discussion in:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086

* Supports composing simple types for Result injection (#362)

* [OPR-362]: Linting whitespace changes

* [OPR-362]: Adds support for composing “executors” inside a final Operation type

This is a convenience class to aid adoption of _Operations_ without requiring types to subclass Operation. Instead, classes only need to conform to Executor, and then can use the Execute class, which support cancellation, and result injection.

* Supports async executors (#363)

* Fixes a finished log message (#365)

The "Operation Did finish" log was using the opposite logic for error logging

* Group's internal queue is non-public; exposes appropriate properties (#361)

* Make GroupOperation's internal queue non-public, and expose appropriate properties on GroupOperation

- Make GroupOperation.queue ~private~internal. (So it can be tested.)
- Expose appropriate run-time editable properties of the
GroupOperation’s queue as properties on GroupOperation.

Specifically:
- public var maxConcurrentOperationCount: Int
- public var suspended: Bool
- public var qualityOfService: NSQualityOfService

- Add tests.

* [OPR-361]: Support underlying queue in Group

* GatedOperation cancels composed operation when gate is closed (#377)

* [OPR-377]: Adds early exit with guard

* [OPR-377]: Refactors GatedOperation execute

* [OPR-377]: Fixes typo

* Result Injection protocol improvements (#378)

* [OPR-378]: Updates result injection APIs

* [OPR-378]: Adds unit tests

* [OPR-378]: Removes unnecessary weak self capture

* Fixes dependency gets added twice if it's direct & indirect (#379)

* [OPR-379]: Adds a failing unit test

* [OPR-379]: Makes indirect dependencies unique set

* Removes TaskOperation from non-macOS platforms (#382)

* Removes AlertPresentation mutual exclusion (#383)

* Adds IgnoredCondition (#385)

* Filters out indirect dependencies which have already been added (#386)

* Fixes issues with ignored condition (#390)

This means that conditions which are ignored mean that the attached operation does not execute, but also does not finish with an error. It’s a nicer use case than GatedOperation. This works by checking the OperationResult for .Ignored and then only cancel() instead of cancelWithError().

Note that if the operation also has .Failed(errors) condition result, in addition to .Ignored then the operation will still not run but this time with errors (as expected).

Note that if the operation also has .Satisfied condition result, in addition to .Ignored then the operation will not run, but without errors.

* NoFailedDependenciesCondition supports ignoring cancelled operations (#397)

Fixes #396. 

* [OPR-396]: NoFailedDependenciesCondition support ignoring cancels

* [OPR-396]: Refactors initializer

* [OPR-396]: Renames the condition

* Ability to add configuration to the next (retried) CloudKitOperation (#395)

* Adds CloudKitOperation.setPrepareForRetryHandler()

* Adds BatchedCloudKitOperation.setPrepareForNextOperationHandler()

* Clean-up

* Updated new APIs, added documentation

-Simpler, cleaner, better APIs.
-Added documentation and examples for the new APIs.

* Add documentation for BatchedCloudKitOperation.

* Updates project header (#399)

* [OPR-399]: Updates the header

* [OPR-399]: Updates the README to point to the new URL for header

* Updates guidelines (#400)

* [OPR-400]: Updates copyright holders to “ProcedureKit”

* [OPR-400]: Adds a code of conduct

* [OPR-400]: Fixes a markdown formatting issue

* [OPR-400]: Adds CONTRIBUTING guidelines

* [OPR-400]: Moves CONTRIBUTING to .github directory

* [OPR-400]: Removes an empty section

* [OPR-400]: Adds instruction on adding verbose logs.

* [OPR-400]: Updates CONTRIBUTING guideline

* [OPR-400]: Updates README too

* [OPR-400]: Fixes some typos

* Creates ProcedureKit project (#401)

* [OPR-401]: Sets up ProcedureKit project

* [OPR-401]: Adds ProcedureKitMobile

This will cover iOS & watchOS

* [OPR-401]: Adds ProcedureKitTV

* [OPR-401]: Fixes Runtime Search Paths

* [OPR-401]: Adds StressTests

* [OPR-401]: Adds ProcedureKitMac

* [OPR-401]: Enables code coverage on all  testable schemes

* [OPR-401]: Adds ProcedureKitCloud

* [OPR-401]: Changes to module imports

* [OPR-401]: Changes Cloud to latest deployment versions

* ProcedureKit CI - Stage 1 (#403)

* [OPR-403]: Changes Stress Tests to only run as part of the ProcedureKitMac scheme

* [OPR-403]: Changes Cloud minimum target versions

* [OPR-403]: Adds tests to CI - ProcedureKit macOS

* [OPR-403]: Fixes Operations mac tests

* [OPR-403]: Fixes Operations tests 2

* [OPR-403]: Fixes Swift version to 2.2

* [OPR-403]: Moves common scripts around

* [OPR-403]: Updates scripts

* [OPR-403]: Changes to the Fastlane name for mac

* [OPR-403]: Updates build dependencies

* [OPR-403]: Sets the correct destination platform

* [OPR-403]: Updates scan invocation

* [OPR-403]: Updates Fastfile

* [OPR-403]: Trying to use which to find bundle

* [OPR-403]: Using quotes

* [OPR-403]: Adds setup first

* [OPR-403]: Putting the whole setup into quotes

* [OPR-403]: Attempting to add multiple lines to the command

* [OPR-403]: Puts it all on one line

* [OPR-403]: Adds more ProcedureKit steps

* [OPR-403]: Fixes error in Stress Tests build settings

* [OPR-403]: Pipline Uploads

* [OPR-403]: Fixes pipelines

* [OPR-403]: Uses pipeline upload correctly

* [OPR-403]: Fixes error in mobile tests

* [OPR-403]: Adds watchOS

* [OPR-403]: Removes automatic code signing

* [OPR-403]: Comments out watchOS builds

* [OPR-403]: Adds TV

* [OPR-403]: Removes ad-hoc code signing

* [OPR-403]: Fixes Operations iOS

* [OPR-403]: Sets iPhone Developer automatic code signing

* [OPR-403]: Updates buildkite agent tags for iOS Simulator

* [OPR-403]: Sets the development team in xcargs

* [OPR-403]: Enables automatic code signing without a team set

* [OPR-403]: Fixes issues with code signing settings for TV

* [OPR-403]: Removes the development team

* [OPR-403]: Puts everything into a single pipeline

* [OPR-403]: Cleans up the pipeline

* [OPR-403]: Sets personal team for mobile unit tests

* [OPR-403]: Updates the Fastlane lane names

* [OPR-403]: Adds a copy frameworks build phase

* [OPR-403]: Removes copy files phase

* [OPR-403]: Comments out problematic build jobs

* [OPR-403]: Removes Operations CI jobs

* ProcedureKit CI - Stage 2 (#404)

* Update CI dependencies (#409)

* [OPR-409]: Updates dependencies and enables pipeline

* [OPR-409]: Fixes YML

* [OPR-409]: Fully specifies the destination

Starting to really not like Fastlane

* [OPR-409]: Switches to iOS 10 simulators.

* [OR-409]: Sets the developer directory

* [OPR-409]: Removes tvOS for Mobile framework

* [OPR-409]: Reorders the jobs

* Add base types to ProcedureKit (#405)

* [OPR-405]: Creates Procedure

* [OPR-405]: Sets the Swift version

* [OPR-405]: Cleans project

* [OPR-405]: Changes to destination

* [OPR-405]: Stops using Fastlane for testing macOS

* [OPR-405]: Adds initial files for ProcedureQueue

* [OPR-405]: Defines ProcedureObserver

* [OPR-405]: Adds the default implementation of ProcedureObserver

* [OPR-405]: Adds the rest of the observer protocols

* [OPR-405]: Adds @available annotations

* [OPR-405]: Adds block based observers

* [OPR-405]: Adds Protector / DispatchQueue extension

* [OPR-405]: Further updates to observers API

* [OPR-405]: Adds extension to Operation

This is for addCompletionBlock - but will be used for more stuff when we get into dependencies

* [OPR-405]: Fixes lint issues

* [OPR-405]: Adds Procedure protocol with AbstractProcedure

* [OPR-405]: Starts interfaces in AbstractProcedure for execute & finish

* [OPR-405]: Adds state transition

* [OPR-405]: Refactors Procedure to be protocol based.

* [OPR-405]: Adds most of the cancellaton functionality

* [OPR-405]: Adds main implementation

With a few TODOs

* [OPR-405]: Fixes available renames

* [OPR-405]: Changes AbstractProcedure back to Procedure

* [OPR-405]: Adds Testing framework

With TestProcedure class

* [OPR-405]: Adds basic API to ProcedureTestCase

* [OPR-405]: Updates dependencies

* [OPR-405]: Commenting out non mac unit tests

Run CI on iOS Simulators is basically impossible on beta version of Xcode.

* [OPR-405]: Adds finishing and cancellation tests

* [OPR-405]: Adds some finishing tests

* Adds Logging (#428)

* [OPR-428]: Adds LogSeverity

* [OPR-428]: Adds logger

* [OPR-428]: Updates logging stuff

* [OPR-428]: Adds logging tests

* Group (#430)

* [OPR-430]: Adds Group

* [OPR-430]: Adds initializers to Group

* [OPR-430]: Adds add child API to Group

* [OPR-430]: Corrects spelling

* [OPR-430]: Adds finishing APIs to Group

* [OPR-430]: Adds extension of unavailable APIs

* [OPR-430]: Adds GroupObserverProtocol

* [OPR-430]: Adds error handling and recovery to Group

* [OPR-430]: Improves group observers API

* [OPR-430]: Adds first group test

* [OPR-430]: Adds some basic tests for Group

* [OPR-430]: Adds more unit test for Group

* [OPR-430]: More tests for group

* Adds User Intent (#439)

* [OPR-439]: Adds UserIntent to Procedure

* [OPR-439]: Adds userIntent to Group

* Stress Tests Phase 1 (#442)

* [OPR-442]: Adds StressTestCase and completion block stress tests

* [OPR-442]: Uses StressLevel directly.

* [OPR-442]: Refactors the test case names

* [OPR-442]: Refactors to remove StressTestCase

Instead the stress function can be added to the base ProcedureKitTestCase

* [OPR-442]: Adds group cancel stress test

* [OPR-422]: Refactors group stress tests

These are currently failing

* [OPR-422]: Refactors schemes, as stress tests are run as part of Mac tests

* [OPR-442]: Updates Stress Tests batches

Uses intermediate BatchProtocol, and exposes a measure API.

* [OPR-422]: Changes the active developer directory

* [OPR-422]: Adds group child finishing order stress test

* [OPR-422]: Fixes incorrect pipeline step

* [OPR-422]: Adds more stress tests for Procedure

* [OPR-422]: Fixes TestError mistake

* [OPR-422]: Changes to use didCancelBlockObserver

Instead of didFinishBlockObserver - there might be a subtle bug here.

* [OPR-422]: Disables some checks - have identified that there is definitely an error in finishing logic

* [OPR-422]: Moves stress tests to their own scheme

* [OPR-422]: Adds stress fastlane

* [OPR-422]: Trying to see how to trigger stress tests

* [OPR-422]: Removing -

* [OPR-422]: Changes the trigger to ProcedureKit

* [OPR-422]: Add the pipeline update step back

* [OPR-422]: Fixes yml

* [OPR-422]: More changes to pipeline template

* [OPR-422]: Fixes the slug

This is case sensitive!

* [OPR-422]: Triggers a different pipeline stress tests

* [OPR-422]: Adds commit message to stress test build

* [OPR-422]: Modifies measure to be a little quicker

* [OPR-422]: Updates baselines with Mac Pro

* [OPR-422]: Fixes mistake with finishing from cancel

* Fix issue with newlines in pipeline upload (#445)

* [OPR-445]: Removes message from upload script

* [OPR-422]: Puts the commit back

* Initial work on Result Injection (#446)

* Adds Dependencies & Conditions (#429)

* [OPR-429]: Adds Condition protocol and class

* [OPR-429]: Adds conditions to procedure and queue

* [OPR-429]: Adds tests for Conditions

Also adds XCTAssertProcedure functions to make verifying Procedure behaviour more consistent.

* [OPR-429]: Adds remaining unit tests for conditions

Still got Ignored Condition to add

* [OPR-429]: Fixes some documentation

* [OPR-429]: Performs the stress tests in the same build

* [OPR-422]: Adds stress tests for conditions

* [OPR-429]: Adds IgnoredCondition

* ProcedureKitError (#437)

* [OPR-437]: Regorganized the Core group

* [OPR-437]: Refactors Errors into ProcedureKitError

* Completes Result Injection API test coverage (#447)

* [OPR-447]: Sorts out ResultInjection

* [OPR-447]: Completes result injection tests

* Fixes Xcode 8 GM issues (#463)

* BlockProcedure (#450)

* [OPR-450]: Adds BlockProcedure

* [OPR-450]: Adds unit tests for map and block procedures

* [OPR-450]: Adds some stress tests for block procedure

* [OPR-450]: Updates stress tests

* [OPR-450]: Fixes Xcode 8 GM escaping issue

* [OPR-450]: Papers over some possible issues with finishing.

In many cases the `should finish after cancelling` logic is returning false.

* [OPR-450]: Removes some excessive logging

* [OPR-450]: Adjusts variation to 15%

* Mutual exclusive conditions (#448)

* [OPR-448]: Adds MutualExclusion

* [OPR-448]: Adds support for adding dependencies for mutual exclusion

* [OPR-448]: WIP on mutual exclusivity

* [OPR-448]: Finishes off test cases for mutual exclusivity

* [OPR-448]: Refactors add condition API to attach condition

I want to make the API consistent - but not choose consistency over intent. So, `add(dependency: myDependency)` makes sense - as it signals that the dependency is already managed by some other queue/system.

Where as for a Condition, we specifically _attach_ it to Procedure instance, and it does not (ideally should not) be managed outside the Procedure.

So, I want the concept of “attaching conditions to procedures” to be the language which is used to describe the behaviour.

* DelayProcedure (#449)

* [OPR-449]: Adds delay procedure

* [OPR-449]: Adds DelayProcedure tests

* Renames Group to GroupProcedure (#468)

* Adds ProcedureKit.podspec (#467)

* Adds NegatedCondition (#471)

* Adds SilentCondition (#472)

* Procedure finishing fixes (#474)

* Resolve finishing issues related to FinishingFrom.
* Add StressTest that covers concurrent calls to finish()
* Revert ProcedureKitTestCase expectation fulfillment back to the main queue.

* Adds BlockCondition (#473)

* Adds NoFailedDependenciesCondition (#470)

* Adds TimeoutObserver (#475)

* [OPR-475]: Adds TimeoutObserver

* [OPR-475]: Fixes issues with TestProcedure

It was not correctly delaying.

* Procedure name and identity (#478)

* [OPR-478]: Adds name and Identity

* [OPR-478]: Fixes some failing tests

* [OPR-478]: Fixes another failing name test

* Adds BlockObserver (#480)

* [OPR-480]: Adds BlockObserver

* [OPR-480]: Tweaks to stress tests

* Adds ComposedProcedure & GatedProcedure (#487)

* RepeatProcedure (#488)

* [OPR-488]: Initial work on RepeatProcedure

* [OPR-488]: Adds remaining test coverage

* RetryProcedure (#491)

* [OPR-491]: Adds RetryProcedure

* [OPR-491]: Unifies the generic init pattern for repeat and retry procedures

* Adds support for Capabilities (#492)

* [OPR-492]: Fixes incorrectly spelt protocol

* [OPR-492]: Adds Capability

Including CapabilityProtocol, GetAuthorizationStatus, Authorize, AuthorizedFor

* Adds BackgroundObserver (#476)

* [OPR-476]: Fixes stress tests

* [OPR-476]: Adds BackgroundObserver

* [OPR-476]: Gets the Mobile test suite working

* [OPR-476]: Switches code coverage on

* [OPR-476]: Adds missing callback

This was causing a failing unit test

* [OPR-476]: Removes unnecessary build phase

* [OPR-476]: Finishes BackgroundObserver tests

* [OPR-476]: Removes verbose logging in test case

* Adds FilterProcedure (#496)

* [OPR-496]: Adds FilterProcedure

* [OPR-496]: Adds filter method for when Result is a sequence

* Adds ReduceProcedure (#497)

* [OPR-497]: Adds ReduceProcedure

* [OPR-497]: Refactors Map, Filter adds FlatMap

MapProcedure is really a TransformProcedure. MapProcedure and FilterProcedure are now simple subclasses of ReduceProcedure, along with FlatMapProcedure.

* Adds NetworkObserver (#498)

* [OPR-498]: Adds NetworkObserver

Additionally, this updated ProcedureKitTestCase to automatically add async expectation fulfills around operations which might be produced by a procedure.

* [OPR-498]: Refactors ProcedureKitTestCase slightly for Swift 3 conventions.

* Adds Location.Capability (#499)

* [OPR-499]: Adds ProcedureKitLocation framework

* [OPR-499]: Supports sychronous dispatch onto the main queue

This is safe to call if already on the main queue.

* [OPR-499]: Adds Capability.Location

* Adds UserLocationProcedure (#500)

* [OPR-500]: Adds UserLocationProcedure

* [OPR-500]: Removes unneeded error struct

* [OPR-500]: Fixes issue with tvOS

* Corrects minimum deployment targets (#503)

Fixes #501

* [OPR-501]: Fixes issues with deployment versions

* [OPR-501]: Setting tvOS to 9.2

* Adds ReverseGeocodeProcedure (#502)

* [OPR-502]: Adds ReverseGeocodeProcedure

* [OPR-502]: Adds ProcedureKitMobile as a build dependency

* [OPR-502]: Fixes a mistake where macOS location tests were requiring iOS simulator

* [OPR-502]: Uses gym to ensure iOS builds ProcedureKitMobile before testing Location

* [OPR-502]: Use scan instead of gym

This is a hack. I want to make sure that when we test ProcedureKitLocation on iOS we have build ProcedureKitMobile.

* Adds ReverseGeocodeUserLocationProcedure (#504)

* [OPR-504]: Adds/renames files

* [OPR-504]: Adds ReverseGeocodeUserLocationProcedure

* [OPR-504]: Rounds out the unit tests on ReverseGeocodeUserLocationProcedure

* Makes procedures open where appropriate (#510)

* Refactors BlockProcedure (#511)

* Adds AnyProcedure (#516)

* [OPR-516]: Removes import foundation

This is done by the prefix header

* [OPR-516]: Adds AnyProcedure

* [OPR-516]: Uses the correct underlying queue throughout AnyProcedure

* Fixes regression of failing release build (#518)

* Renames AuthorizationStatusProtocol to AuthorizationStatus (#519)

* Renames capability reated procedures (#520)

* Renames attach(condition: Condition) to add (#521)

* Adds Capability.CloudKit (#523)

* [OPR-523]: Adds Capability.CloudKit

* [OPR-523]: Enables CI builds for CloudKit stuff on iOS and tvOS

* Adds ProcedureKitNetwork framework (#524)

* [OPR-524]: Adds ProcedureKitNetwork framework

* [OPR-524]: Adds Network to CI jobs

* [OPR-524]: Renames Stress Tests job

* [OPR-524]: Shares the network scheme

* [OPR-524]: Imports Foundation instead of Cocoa

* [OPR-524]: Forces Stress Tests onto a non-simulator agent

* Adds NetworkDataProcedure (#525)

* [OPR-525]: Adds NetworkDataProcedure

* [OPR-525]: Fixes up some unit tests

* [OPR-525]: Adds missing test coverage

* Moves TestableNetwork into TestingProcedureKit framework (#526)

* Refactors injectDependency API to be an extension on ProcedureProtocol instead. (#527)

* Adds transform block result injection API (#528)

* [OPR-528]: Refactors result injection

Uses an intermediatory injectResult(from: via:) API, which allows the caller to provide a throwing block to transform the result into the requirement.

* [OPR-528]: Removes unneeded return

* [OPR-528]: Fixes error in ProcedureKitLocation

* Adds default empty implementations some queue delegate methods (#531)

Only added the will-do-something ones.

Fixes #530

* Adds space in the repo for presentations  (#533)

* [OPR-533]: Adds CocoaHeads Stockholm talk

Contact @danthorpe if you want the original Keynote file.

* [OPR-533]: Adds Sky-UK iOS Community Talk

* [OPR-533]: Adds a presentations README

* Disables the log for AnyProcedure (#534)

* Fixes bug where GroupProcedure collects errors from children after its been cancelled (#532)

* [OPR-532]: Adds failing test

* [OPR-532]: Checks cancelled state of the group

We can exit this delegate callback early if the group has already been cancelled.

* [OPR-532]: Removes default implementation of willFinish

It seems that adding default implementations here causes some odd behaviour / intermittent crash where this is overwritten in the QueueDelegate.

* [OPR-532]: Fixes a unit test which is now mis-counting errors.

* Adds .then { } API (#536)

* [OPR-176]: Adds then extension on Operation

* [OPR-176]: Implements .then { } API

* [OPR-176]: Adds enqueue method to a collection of Operations

* [OPR-176]: Fixes header docs

* Removes default argument for session in NetworkDataProcedure (#538)

* Tweaks the cancel block procedure stress tests (#539)

There might be an underlying issue. As normally a batch of 10_000 finishing in ~ 5 seconds. But sometimes fails because it times out, meaning that an expectation is not getting fulfilled.

* Moves ProcedureKit imports to umbrella headers (#540)

* [OPR-540]: Putting the appropriate imports into umbrella headers

* [OPR-540]: Fixing issues with importing ProcedureKit into TestingProcedureKit

* Updates ProcedureKit podspec with subspecs (#508)

* [OPR-508]: Lints podspec without an warnings or errors.

* [OPR-508]: Fixes errors running tests

* Adds ResilientNetworkProcedure  (#537)

* [OPR-537] Adds ResilientNetworkProcedure

* [OPR-537]: Updates retry request with error code

* [OPR-537]: Adds edge case for ResilientNetworkProcedure

In some situations, the HTTP status code might well require (depending on the behaviour) a retry.

* [OPR-537]: Fixes simple unit tests

* Refactor ResultInjection to use PendingValue enum (#541)

* [OPR-541]: Refactors ResultInjectionProtocol to use PendingValue enum

* [OPR-541]: Renames ResultInjectionProtocol to ResultInjection

* Fixes BlockProcedure stress tests (#544)

* [OPR-544]: Fix test__cancel_block_procedure() failures

It was possible for the testing BlockProcedure to finish prior to the
`block.cancel()` call, which would result in some of the
BlockProcedures never cancelling (as they had finished first), and
a failing test.
Fixed by using a semaphore inside the BlockProcedure’s block.
Additionally, the test now waits for all BlockProcedures to cancel
*and* finish.

* [OPR-544]: Added a new stress test for BlockProcedure cancelling & finishing behavior (allowing for possible races between cancelling and finishing)

* Fixes ExclusivityManager synchronization bug (#545)

Fixes #543 

The ExclusivityManager was using `DispatchQueue.initiated`, which
returns a global **concurrent** queue, however its internals are
dependent upon **serial** execution of add/remove.
Modified to use a serial queue.

* Adds ResultProcedure and overloads injectResult(from:) (#546)

* Adds HTTPResult<Payload> (#547)

* Fix test crashes caused by QueueTestDelegate (#549)

QueueTestDelegate was not thread-safe. This could result in crashes running random tests.
Fixed by making QueueTestDelegate’s methods thread-safe.

* Adds ProcedureKitTestCase wait function that takes an array (#552)

* Adds TestingProcedureKit podspec (#553)

* Adds Mutual Exclusivity concurrency testing (#550)

* Add ConcurrencyTestCase

Exposes functionality to test operation concurrency.

* Add Mutual Exclusivity concurrency tests

* Refactored ConcurrencyTestCase

* Refactored ConcurrencyTestCase

* Adds didExecuteObserver (#554)

* [OPR-554]: Adds code with failing test

* [OPR-554]: Calls didExecuteObservers

* [OPR-554]: Fixes a typo

* [OPR-554]: Adds some documentation to the DidExecuteObserver

* Fixes mistake in Fastfile (#557)

* [OPR-557]: Fixes error in Fastfile

* [OPR-557]: Removes duplicate scan

I remember now, as part of location, we used to build Mobile too - because there was a dependency on iOS. But this has since been removed.

* Fixes release configuration issues with Xcode 8.1 (#559)

Fixes #548 

* [OPR-548]: Fixes issue with Xcode 8.1 release configuration

* [OPR-548]: Fixes some SwiftLint warnings.

* [OPR-548]: Fixes Xcode project warnings in Xcode 8.1

* Adds GroupProcedure concurrency tests (#556)

* Add GroupConcurrencyTestCase

* Add GroupProcedure.maxConcurrentOperationCount tests

* Fixes registrar typo (#562)

* Adds NetworkDownloadProcedure. (#565)

The implementation for class and test is largely inspired by
`NetworkDataProcedure` class.

* Adds NetworkUploadProcedure. (#567)

* Add NetworkUploadProcedure.

The implementation class and test has been largely inspired by
`NetworkDataProcedure`.

The requirement type is currently a pending value of a tuple.
Maybe would it make more sense to create a dedicated struct to add more
clarity in the case of dependencies injection ?

* Use an `HTTPRequirement` struct for requirement.

As discussed, an `HTTPRequirement` struct is used instead of a tuple.

* Fixes Condition to support ResultInjection (#566)

* [OPR-566]: Replaces Condition result with PendingValue<ConditionResult>

* [OPR-566]: Refactors how conditions are evaluated

This fixes a existing issue where the ConditionEvaluation enum was basically just like ConditonResult, except that it could hold an array of errors.

This has been resolved by using an internal error type `ProcedureKitError.FailedConditions` to collect multiple errors from failed conditons, so that we can reduce a sequence of `ConditionResult`s into a single one.

* [OPR-566]: Explicitly adds a Result typealias

* [OPR-566]: Fixes error where cancelled conditions would throw a fatal error.

* [OPR-566]: Removes verbose log

* Adds ProcessProcedure. (#570)

* Add ProcessProcedure.

The class has been largely inspired by the original `TaskOperation`.
Refers to #568.

* Apply requested changes.

Correctly implement `Equatable` for sub-error enum.
Use camel case for the enum.
Fix closure self semantics.

* Calls TestableReverseGeocoder completionHandler on the main queue (#572)

* Improves performance of adding observers

* Procedure.add(observer:) performance tweak

Append directly to the protected observers array.

* Fix swiftlint `variable_name` warning

* Makes ProcedureQueue.add(operation: Operation) method open (#578)

* Fixes NetworkObserver thread-safety (#576) (#577)

* Fix NetworkObserver thread-safety

By fixing NetworkActivityController `start()`/`stop()` thread-safety.
(And making private methods/variables private.)

* NetworkObserver test fixes

* Reduce test delay

* Additional GroupProcedure tests (#579)

* Adds CloudKitProcedure (#542)

* [OPR-542]: Adds shell of CloudKit files

* [OPR-542]: Adds extensions for CKOperation

* [OPR-542]: Adds extensions for CKDatabaseOperation

* [OPR-542]: Adds extensions for CKAcceptSharesOperation

* [OPR-542]: Adds extensions for CKDiscoverAllContactsOperation

* [OPR-542]: Adds extensions for CKDiscoverAllUserIdentifiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds extensions for CKDiscoverUserInfosOperation

* [OPR-542]: Adds extensions for CKFetchDatabaseChanges

* [OPR-542]: Adds extensions for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds extensions for CKFetchRecordChangesOperation

* [OPR-542]: Moves the interface into the extension files

* [OPR-542]: Fixes dispatchQueue

* [OPR-542]: Adds extensions to CKFetchRecordsOperation

* [OPR-542]: Adds extensions for CKFetchRecordZoneChangesOperation

* [OPR-542]: Removes unnecessary public properties

* [OPR-542]: Adds extensions for CKFetchRecordZonesOperation

* [OPR-542]: Adds extensions for CKFetchShareMetadataOperation

* [OPR-542]: Adds extensions for CKFetchShareParticipantsOperation

* [OPR-542]: Adds extensions for CKFetchSubscriptionsOperation

* [OPR-542]: Adds extensions for CKMarkNotificationsReadOperation

* [OPR-542]: Adds extensions for CKModifyBadgeOperation

* [OPR-542]: Adds extensions for CKModifyRecordsOperation

* [OPR-542]: Adds extensions for CKModifyRecordZonesOperation

* [OPR-542]: Adds extensions for CKModifySubscriptionsOperation

* [OPR-542]: Adds extensions for CKQueryOperation

* [OPR-542]: Adds missing APIs for error handlers

* [OPR-542]: Adds testable CK operation classes

* [OPR-542]: Adds tests for CKOperation, CKDatabaseOperation and CKAcceptSharesOperation

* [OPR-542]: Removes missing test cases from tvOS

* Small typo fix

* Adds tests for CKDiscoverAllContactsOperation

* Adds tests for CKDiscoverAllUserIdentitiesOperation

* Adds tests for CKDiscoverUserIdentitiesOperation

* Adds tests for CKDiscoverUserInfosOperation

* [OPR-542]: Adds tests for CKFetchAllChanges protocol

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordsOperation

* [OPR-542]: Added missing `recordZoneFetchCompletionBlock` for CKFetchRecordZoneChangesOperationProtocol extensions

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Minor typo fix

To follow the original API naming, change
`setMarkNotificationReadCompletionBlock` to
`setMarkNotificationsReadCompletionBlock`.

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds tests for CKModifySubscriptionsOperation

* [OPR-542]: Adds tests for CKQueryOperation

* [OPR-542]: Fixes whitespace in test cases

* [OPR-542]: Adds CloudKitProcedure<CKAcceptSharesOperation> tests

* [OPR-542]: Fixes tests on tvOS. Again.

* [OPR-542]: Adds tests for CKDiscoverAllContactsOperation

* [OPR-542]: Adds tests for CKDiscoverAllUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserIdentitiesOperation

* [OPR-542]: Adds tests for CKDiscoverUserInfosOperations

* [OPR-542]: Adds tests for CKFetchDatabaseChangesOperation

* [OPR-542]: Unifies testing of common properites

* [OPR-542]: Adds tests for CKFetchNotificationChangesOperation

* [OPR-542]: Adds tests for CKFetchRecordChangesOperation

* [OPR-542]: Adds test for CKFetchRecordsOperation

* [OPR-542]: Adds tests for CKFetchRecordZoneChangesOperation

* [OPR-542]: Adds test for CKFetchRecordZonesOperation

* [OPR-542]: Adds tests for CKFetchShareMetadataOperation

* [OPR-542]: Adds tests for CKFetchShareParticipantsOperation

* [OPR-542]: Fixes inconsistently named tests

* [OPR-542]: Adds tests for CKFetchSubscriptionsOperation

* [OPR-542]: Adds tests for CKMarkNotificationsReadOperation

* [OPR-542]: Adds tests for CKModifyBadgeOperation

* [OPR-542]: Adds tests for CKModifyRecordsOperation

* [OPR-542]: Adds tests for CKModifyRecordZonesOperation

* [OPR-542]: Adds test for CKModifySubscriptionsOperation

* [OPR-542]: Adds test for CKQueryOperation

* [OPR-542]: Adds tests which trigger default retry behavior

* [OPR-542]: Adds tests for set/get all errors handlers

* [OPR-542]: Adds tests for custom error handlers

* Adds Profiler (#573)

* Implement Profiler as specified in #569.

The implmentation is largely inspired by the original `Profiler.swift`
file.

* Add first set of tests.

The test has been largely inspired by the original tests classes.

I have a commented test taht fails. After trying to debug for a while, I
suspect maybe an issue inside GroupProcedure or the original
implementation.

* Apply requested changes.

Perform changes as requested.

* Adds public initialiser to HTTPRequirement (#586)

Declaring a constructor for the `HTTPRequirement` allows the
construction of the struct without any issue.

* Removes GroupProcedureObserver protocol (#583)

Instead ProcedureObserver takes over this responsibility.

* [OPR-574]: Cleans up white space & style for consistency

* [OPR-574]: Uncomments failing test

* [OPR-574]: Adds new API to ProcedureObserver protocol

* [OPR-574]: Removes temporary print statements

* [OPR-574]: Refactors to support willAdd & didAdd observer callbacks.

* [OPR-574]: Removes commented out line.

* [OPR-574]: Removes group observers.

* [OPR-574]: Removes extraneous logging in some tests

* [OPR-574]: Makes add(observer:) open for overriding

* [OPR-574]: Adds some documentation comments to public interfaces

* Supports Arbitrary mutual exclusion category names (#587)

Fixes #580.

* [OPR-580]: Supports arbitrary mutual exclusion category names

* [OPR-580]: Fixes default category for AuthorizedFor

* Adds NetworkReachableProcedure (#563)

* [OPR-563]: Adds Reachability functionality

* [OPR-563]: Adds additional files for testing support

* [OPR-563]: Adds tests for Reachability

* [OPR-563]: Adds basis of NetworkReachableProcedure

* [OPR-563]: Adds simple network reachability procedure tests

* [OPR-563]: Fixes issue with Protector write being synchronous.

* [OPR-563]: Refactors DeviceReachability slightly

* [OPR-563]: Changes Protector behavior back to be non-blocking

* [OPR-563]: Fixes Reachability.Device

* [OPR-563]: Adds NetworkProcedure and ProcedureKitNetworkError

* [OPR-563]: Fixes for network error tests

* [OPR-563]: Adds remaining tests for Reachable procedure

* [OPR-563]: Removes unnecessary logging

* Refactors produce API (#588)

* Add failing test

* Test tweaks

* Changes to Procedure.produce(operation:) handling

Fixes failing test case, and simplifies execution flow.
Changes `willEnqueue()` to `willEnqueue(on: ProcedureQueue)`.
`func produce(operation: Operation)` now throws.

* Ported additional test case from Operations 3.x.

* swiftlint tweak

* Fixed mobile tests.

* Adds missing equality cases for ProcedureKitError.Context (#591)

Fixes #589

* Supports merging collections of ResultInjection Procedures (#593)

* [OPR-593]: Adds gather and reduce APIs

* [OPR-593]: Removes the rethrows

While the nextPartialResult closure can throw, this error is not re-thrown. Instead, because this block is executed after the receiver’s procedures have all finished, the error means that the `ResultProcedure` will finish with an error.

* [OPR-593]: Adds test case for throwing closure

* [OPR-593]: Refactors gather() so that it is a specialization of new flatMap API

* Improves how stress tests are run in CI (#594)

* [OPR-594]: Updates pipeline queues

* [OPR-594]: Fixes yaml

* [OPR-594]: Disables Thread Sanitizer for Stress Tests

* [OPR-594]: Uses Release configuration for stress tests

* Fix StressTestCase Batch counters thread-safety (#555) (#596)

* Fixes public access levels for CKProcedure (#599)

* Fixes some RepeatProcedure thread-safety issues (#597)

Fix issues identified by an audit and Thread Sanitizer

* Fixes Procedure & Support thread-safety (#598)

* Change Protector.write() to be synchronous (and optionally return a value from the block)

Thread Sanitizer identified a data race caused by the combination of
the prior asynchronous `write()` and deinitialization.

* Explicitly `import Dispatch` in Support.swift

Fixes an occasional Xcode warning display glitch.

* Fix Protector.read() to no longer require an `escaping` block

* Adds back `Protector.write(_:completion:)`

Although, like the new write(_:) method, this is now synchronous.

* Wrap all properties of Procedure in a Protector to ensure thread-safety

`errors`, `observers`, `directDependencies`, `conditions` (and
associated methods) are now thread-safe

* Fix comment formatting

* Removes @testable import (#600)

Exposes NSLock and NSRecursiveLock extensions

* Add RepeatProcedure cancellation stress test (#602)

* Adds more GroupProcedure test coverage (#603)

* Additional / improved GroupProcedure test cases

* Remove unused private setter

* Refactors of Result Injection APIs (#601)

* [OPR-601]: Renamed PendingResult to PendingProfileResult

* [OPR-601]: Adds protocols for Input & Output

* [OPR-601]: Refactors for InputProcedure & OutputProcedure

* [OPR-601]: Refactors ReduceProcedure as a TransformProcedure subclass

* [OPR-601]: Refactoring for InputProcedure & OutputProcedure

* [OPR-601]: Refactoring Condition to use Result<Bool>

* [OPR-601]: Refactors ProcedureKitNetwork result injection

* [OPR-601]: Refactors Location for result injection

* [OPR-601]: Removes ResultInjection.swift

* [OPR-601]: Removes left over properties

* [OPR-601]: Tidies up ResultProcedure & TransformProcedure

* [OPR-601]: Adds finish(withResult:) API

* [OPR-601]: Refactors to use finish(withResult:)

* [OPR-601]: Renames HTTPRequirement & HTTPResult

* Renames Result to ProcedureResult (#605)

* [OPR-605]: Renames Result to ProcedureResult

Just to help with any interop issues with antitypical/Result

* [OPR-605]: Renames Result to ProcedureResult

* Adds AsyncBlockProcedure  (#606)

* [OPR-606]: Adds AsyncBlockProcedure

As a specialization of AsyncResultProcedure

* [OPR-606]: Moves async block tests into same file

* [OPR-606]: Adds AsyncTransformProcedure

* Adds @escaping marker to the FinishingBlock (#607)

* Fixes NetworkActivityController internal timer (#608)

* NetworkActivityController's delayed hide should occur on the queue

Fixes data race.

* Remove outdated test

* NetworkDataProcedure, NetworkDownloadProcedure, NetworkUploadProcedure thread-safety (#609)

* Adds NetworkProcedure (#561)

* [OPR-561]: Refactoring ResilientNetworkProcedure

- Supports request timeout
- Adds HTTPStatusCode where we only even consider retrying client or server errors.
- Adds some initial tests

* [OPR-561]: Refactors NetworkResilience

* [OPR-561]: Refactor to unify reachable & resilience network procedures

* [OPR-561]: Adds resilience error handling support

This is so that even if the network request “succeeds” but results in say, a server error, we will still trigger retries.

* [OPR-561]: Fixes typos

* Add missing imports to make Xcode happier (#611)

* Add explicit imports to the top of ProcedureKit files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitCloud files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitMobile files
This makes Xcode happier.

* Add missing imports to the top of ProcedureKitLocation files
This makes Xcode happier.

* Fixes BackgroundObserver data race (#614)

* Makes NetworkObserver cross-platform (#613)

* NetworkObserver and NetworkActivityController cross-platform work

On all platforms, the following initializers are available:
`NetworkObserver.init(controller: NetworkActivityController)`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0,
indicator: NetworkActivityIndicatorProtocol)`

To implement your own network activity indicator display, conform to
`NetworkActivityIndicatorProtocol`. NetworkActivityController ensures
that all accesses of the indicator’s `networkActivityIndicatorVisible`
property are serialized on the main queue.

On iOS (but *not* in application extensions), the following convenience
initializers are available that utilize `UIApplication.shared` to
display/hide the network activity indicator in the status bar:
`NetworkObserver.init()`
`NetworkActivityController.init(timerInterval: TimeInterval = 1.0)`
`NetworkActivityController.shared`

* [OPR-612]: Moves NetworkObserver into Network framework

* [OPR-612]: Moves NetworkObserver into ProcedureKit

Keeps iOS non-extension related elements in ProcedureKitMobile

* Add documentation

* Fixes BackgroundObserver on iOS 8.x (#615)

To support iOS < 9.0 and macOS < 10.11, NotificationCenter observers
**must** be properly removed, or a crash may result.

* Fixes DelayProcedure thread-safety (#616)

* Fixes to Location related procedures (#619)

* Capability.Location should set its registrar's delegate to nil on deinit.

CLLocationManager’s delegate is `unowned(unsafe)`, and we must ensure
it is set to nil before the object goes away. The only strong reference
to the delegate that Capability.Location sets is stored within
Capability.Location.

* LocationCapabilityTests tweaks

Explicitly set the test CLLocationManager’s `delegate` back to nil.
Explicitly wait on `capability.requestAuthorization` to fulfill an
expectation.

* ReverseGeocodeProcedureTests tweaks

* Fix an occasional crash running the Location tests

It seems there may be an edge case in CoreLocation triggered when
creating (and releasing) lots of CLLocationManager instances (as
previously happened when each test, using its own
TestableLocationServicesRegistrar, created a “fake” CLLocationManager).

Change `TestableLocationServicesRegistrar`’s “fake” CLLocationManager
(which is only used to populate a parameter in the delegate callbacks)
to a static class variable.

* Compiles out SystemConfiguration related stuff from watchOS (#621)

* Adds an All subspec (#623)

* Adds missing imports in TestingProcedureKit (#625)

Noticed this issue after doing some integration testing via CocoaPods

* Network*Procedure tweaks (#626)

* Resolve cancellation race condition in Network*Procedure

Must check `!isCancelled` inside the `stateLock`, or it is possible for
a
`NetworkDataProcedure`/`NetworkDownloadProcedure`/`NetworkUploadProcedur
e` that is cancelled after the `execute()` function is called, but
before the acquisition of the `stateLock` inside it, to continue to
create a network task.

* Mark `task` as `private(set)`

The `task` variable should not be set outside of the
`NetworkDataProcedure` / `NetworkDownloadProcedure` /
`NetworkUploadProcedure`.

* Memory leaks fixes highlighted by Visual Memory Debugger (#624)

* TimeoutObserver should capture a weak reference to the procedure

* RetryIterator should not maintain a strong reference to the RetryProcedure

RetryIterator’s RetryFailureInfo (`info`) property is set right before
`addNextOperation()` is called, which calls `next()` on the
RetryIterator (which then uses the RetryFailureInfo).

Ultimately, the RetryFailureInfo contains strong references to the
RetryProcedure. And since the RetryProcedure owns the RetryIterator,
which owns the RetryFailureInfo… We end up with a reference cycle.

As an immediate quick fix, since the RetryFailureInfo is only used in
the call to `addNextOperation()`, set it back to `.none` after the call.

* Add test to catch reference cycles in RetryProcedure

(Fixed by prior commit.)

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Revert "GroupProcedure: ensure that internal queue is emptied on deinit"

This reverts commit f2b7176fc8a96e841c8829f8d3b903633c50e883.

* GroupProcedure: ensure that internal queue is emptied on deinit

Previously, a GroupProcedure that was created and released but never
added to a queue would leak the child operations on its internal
OperationQueue. To ensure that it is safe to release a GroupProcedure
in all circumstances, add a `deinit` handler that explicitly cancels
all operations on the queue, and also ensures that the queue is not
suspended (so the queue will handle the clean-up).

* Procedure: Use an autoreleasepool in `start()` override

Replicate the `NSOperation.start()` autorelease behavior by pushing an
autoreleasepool before calling `main()`, and popping after `main()`
returns.
This is particularly important because we override the default
`start()` and `main()` behavior, and our `main()` calls the Procedure
subclass’s `execute()` (and we need to ensure that `execute()`, which
is running on a background thread, has an autoreleasepool).

* Resolves cancellation race condition in Network*Procedure (#627)

The internal cancel observer should be a DidCancelObserver.

* Adds step to CI for CocoaPod integration (#630)

* [OPR-630]: Adds TryProcedureKit trigger

* [OPR-630]: Sets the correct commit

* [OPR-630]: Lowercase pipeline name

* [OPR-630]: Fixes a pipeline typo

* [OPR-630]: Renames cocoapods branch in TryProcedureKit

* Fixes copy/paste typos (#634)

Fixes #633.

* Supports result injection in NetworkProcedure (#632)

Closes #631. 

* [OPR-32]: Makes NetworkProcedure conform to OutputProcedure

* [OPR-632]: Adds convenience API for injecting payload from network

* [OPR-632]: Adds tests for injectPayload(fromNetwork:)

* Removes the fatal override of waitUntilFinished() (#635)

* Adds UIProcedure & AlertProcedure (#592)

UIProcedure & AlertProcedure

* ProcessProcedure improvements & thread-safety (#639)

* Move ProcessProcedureTests to the "Mac Tests" group

* ProcessProcedure thread-safety

`NSTask`/`Process` is listed as a Thread-Unsafe …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant