Latest 0.2.4
Homepage https://github.com/sisoje/RHBOperations
License MIT
Platforms ios 8.0, watchos 2.0, osx 10.9, tvos 9.0
Dependencies RHBMutations
Authors

[![CI Status](http://img.shields.io/travis/Lazar Otasevic/RHBOperations.svg?style=flat)](https://travis-ci.org/Lazar Otasevic/RHBOperations)
Version
License
Platform

Usage

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 {
                return
            }
    }

2. Queuing a throwable block with success and catch

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

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

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

    RHBThrowableBlockInOperation {operation in
            XCTAssert(!operation.isCancelled)
            throw RHBTestError.x
        }.onCatch {error in
            XCTAssert(RHBTestError.x == error as! RHBTestError)
        }.onSuccess {
            XCTFail()
        }.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()

Installation

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

pod 'RHBOperations'

Author

Lazar Otasevic, [email protected]

License

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": "https://github.com/sisoje/RHBOperations",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Lazar Otasevic": "[email protected]"
    },
    "source": {
        "git": "https://github.com/sisoje/RHBOperations.git",
        "tag": "0.2.4"
    },
    "social_media_url": "http://twitter.com/redhotbits",
    "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