Latest 0.1.0
Homepage https://github.com/SiarheiFedartsou/When
License MIT
Platforms ios 8.0
Dependencies Result
Authors

When

CI Status
Version
License
Platform

Lightweight library for waiting for completion of several concurrent tasks.

Getting Started

Library works with asynchronous operations wrapped to Job struct. To wrap your asynchronous task just write:

func findPerson(byId id: String, completionHandler: @escaping (Result<Person, PersonError>) -> Void) {
  // some asynchronous work
}
func findPersonJob(id: String) -> Job<Person> {
  return Job { onSuccess, onFailure in
    findPerson(byId: id) { result in
      switch result {
      case let .success(person):
        onSuccess(person)
      case let .failure(error):
        onFailure(error)
      }
    }
  }
}

Then you can use when function to wait for completion of several jobs:

 when(findPersonJob(id: "personA"), findPersonJob(id: "personB"), onSuccess: { personA, personB in
            // do something with `personA` and `personB`
        }, onError: { error in
            // handle error
        })

For cases when your asynchronous method signature is similar to findPerson(byId:completionHandler:) function above(list of parameters at the beginning, then completionHandler that takes Result type) When has special function wrap which allows easily wrap such methods to jobs:

when(wrap(findPerson(byId:completionHandler:))("personA"), 
     wrap(findPerson(byId:completionHandler:))("personB"), 
     onSuccess: { personA, personB in
       // do something with `personA` and `personB`
     }, 
     onError: { error in
       // handle error
     })

Also you can easily implement your own wrap functions. Just see Wrap.swift for example. Pull requests with new wrap functions are welcome!

Requirements

Installation

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

pod "JustWhen"

Author

SiarheiFedartsou, [email protected]

License

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

Latest podspec

{
    "name": "JustWhen",
    "version": "0.1.0",
    "summary": "Lightweight library for waiting for completion of several concurrent tasks.",
    "description": "Lightweight library for waiting for completion of several concurrent tasks. :)",
    "homepage": "https://github.com/SiarheiFedartsou/When",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "SiarheiFedartsou": "[email protected]"
    },
    "source": {
        "git": "https://github.com/SiarheiFedartsou/When.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "When/Classes/**/*",
    "dependencies": {
        "Result": [
            "~> 3.2.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This