* 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
* [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:
https://github.com/danthorpe/Operations/pull/293
https://github.com/danthorpe/Operations/pull/358#discussion_r70167086
* [3.0.0]: Updates the Changelog
* [3.0.0]: Fixes linting issue related to OpenInSafariOperation