Latest 0.2.1
Homepage https://github.com/fmo91/FOTask
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Introduction

FOTask is a microframework (less than 100 LOCs), with a single objective in mind: separation of concerns.
Every subclass of Task executes an action.
Tasks can be composed in more complex Tasks, or parallelized without effort.

Example usage

Suclassing Task:

final class GetUserTask<Int, Task> {
    override func perform(_ input: Int, onSuccess: @escaping (String) -> Void, onError: @escaping (Error) -> Void) {
        ApiClient("https://somecoolapi.com/users/(input)", .get,
            onSuccess: { (json: Any) in
                onSuccess(User(json: json))
            }, 
            onError: { (error: Error) in
                onError(error)
            }
        ) 
    }
}

Using Task:

let getUserTask = GetUserTask()

getUserTask.perform(3,
    onSuccess: { (user: User) in
        print(user.name)
    },
    onError: { (error: Error) in
        print("An error ocurred.")
    }
)

Composing Tasks:

let getUserWithIDTask = GetUserTask()
let getPostsFromUserTask = GetPostsFromUserTask()

let getPostsFromUserID = getUserWithIDTask => getPostsFromUserTask

getPostsFromUserID.perform(3,
    onSuccess: { (posts: [Post]) in
        print(posts.count)
    },
    onError: { (error: Error) in
        print("An error ocurred.")
    }
)

Parallelize Tasks

let getALotOfUserNames = Task.parallel(
    [
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName(),
        GetUserName()
    ],
    reduce: { (userNames: [String]) -> [String] in
        return userNames
    }
)

getALotOfUserNames.perform(Void(),
    onSuccess: { userNames in
        print(userNames)
    },
    onError: { error in
        print("An Error!")
    }
)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0 or above.
  • Swift 3.0 or above.

Installation

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

pod "FOTask"

Coming soon

  • An explanatory Medium post
  • More documentation
  • More examples
  • More functional features?

Author

fmo91, [email protected]

License

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

Latest podspec

{
    "name": "FOTask",
    "version": "0.2.1",
    "summary": "Object oriented Swift tasks microframework with concurrency and composition.",
    "description": "Object oriented Swift tasks microframework with concurrency and composition.",
    "homepage": "https://github.com/fmo91/FOTask",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "fmo91": "[email protected]"
    },
    "source": {
        "git": "https://github.com/fmo91/FOTask.git",
        "tag": "0.2.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "FOTask/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This