Latest 0.2.4
License MIT
Platforms ios 8.0, watchos 2.0, osx 10.9, tvos 9.0
Dependencies RHBMutations

[![CI Status]( Otasevic/RHBOperations.svg?style=flat)]( Otasevic/RHBOperations)


This POD introduces a concept called "operation (aware) block" and allows queing such blocks into the standard OperationQueue, trough extension. This alows simple cancellation control.

Also, this POD provides mechanism wrapped arround "operation blocks" concept to achieve queueing of blocks that can throw, with flexible, optional catch and success blocks and optional queue for executing success and catch blocks.

NOTE: For Objective-C use

#import "RHBOperations-swift.h"

1. Queuing an "operation block"

Example of queuing an "operation block" that takes too much time and can be cancelled:

    queue.rhb_add {operation in
        for _ in 0...1000 {     
         Thread.sleep(forTimeInterval: 1)
            if operation.isCancelled {

2. Queuing a throwable block with success and catch

Since catch and success block are optional, one can write:

    RHBThrowableBlock {
        /// some work
   }.addTo(operationQueue: queue)

Now here is the full verion with catch, success and re-queueing:

    RHBThrowableBlockInOperation {operation in
            throw RHBTestError.x
        }.onCatch {error in
            XCTAssert(RHBTestError.x == error as! RHBTestError)
        }.onSuccess {
        }.successAndCatch(onQueue: successAndCatchQueue).addTo(operationQueue: queue)

3. Utility methods

Very often one needs a serial queue. It is made simply using RHBMutations:

let queue = OperationQueue().rhb_mutated(maxConcurrentOperationCount: 1)

Or using a wrapper:

let queue = OperationQueue.rhb_newSerialQueue()


RHBOperations is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'RHBOperations'


Lazar Otasevic, [email protected]


RHBOperations is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "RHBOperations",
    "version": "0.2.4",
    "summary": "Queuing "operation blocks" with easy cancellation controll using underlying operation. Support for catch and success blocks.",
    "description": "With this pod you get queuing "operations blocks" into standard OperationQueue to have easy cancellation controll using underlying operation. Support for catch and success blocks..",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Lazar Otasevic": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.4"
    "social_media_url": "",
    "platforms": {
        "ios": "8.0",
        "watchos": "2.0",
        "osx": "10.9",
        "tvos": "9.0"
    "source_files": "RHBOperations/Classes/**/*",
    "dependencies": {
        "RHBMutations": []

Pin It on Pinterest

Share This