All Projects → nrkno → Eventually

nrkno / Eventually

Licence: MIT license
A Swift Future/Promise library that can be used to model and transform asynchronous results

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to Eventually

Promise
Promise / Future library for Go
Stars: ✭ 149 (+684.21%)
Mutual labels:  promise, futures
Q
A platform-independent promise library for C++, implementing asynchronous continuations.
Stars: ✭ 179 (+842.11%)
Mutual labels:  promise, futures
PromisedFuture
A Swift based Future/Promises framework to help writing asynchronous code in an elegant way
Stars: ✭ 75 (+294.74%)
Mutual labels:  promise, futures
swift-futures
Demand-driven asynchronous programming in Swift
Stars: ✭ 32 (+68.42%)
Mutual labels:  futures
variadic future
Variadic, completion-based futures for C++17
Stars: ✭ 41 (+115.79%)
Mutual labels:  futures
combine-promises
Like Promise.all(array) but with an object instead of an array.
Stars: ✭ 181 (+852.63%)
Mutual labels:  promise
more-executors
Library of composable Python executors
Stars: ✭ 18 (-5.26%)
Mutual labels:  futures
routeros-client
Abstraction layer over the node-routeros API
Stars: ✭ 63 (+231.58%)
Mutual labels:  promise
Promise
Asynchronous Programming with Promises
Stars: ✭ 15 (-21.05%)
Mutual labels:  promise
freenom
🌐 Feenom Promise/Async/Await
Stars: ✭ 19 (+0%)
Mutual labels:  promise
wise-river
Object streaming the way it should be.
Stars: ✭ 33 (+73.68%)
Mutual labels:  promise
easy-promise-queue
An easy JavaScript Promise queue which is automatically executed, concurrency controlled and suspendable.
Stars: ✭ 31 (+63.16%)
Mutual labels:  promise
oledb
A small promised based module which uses edge.js to connect to an OLE DB, ODBC or SQL database.
Stars: ✭ 28 (+47.37%)
Mutual labels:  promise
ray tutorial
An introductory tutorial about leveraging Ray core features for distributed patterns.
Stars: ✭ 67 (+252.63%)
Mutual labels:  futures
promise
Common interface for simple asynchronous placeholders.
Stars: ✭ 66 (+247.37%)
Mutual labels:  promise
reactphp-child-process-promise
No description or website provided.
Stars: ✭ 12 (-36.84%)
Mutual labels:  promise
nice-grpc
A TypeScript gRPC library that is nice to you
Stars: ✭ 120 (+531.58%)
Mutual labels:  promise
future.callr
🚀 R package future.callr: A Future API for Parallel Processing using 'callr'
Stars: ✭ 52 (+173.68%)
Mutual labels:  futures
organiser
An organic web framework for organized web servers.
Stars: ✭ 58 (+205.26%)
Mutual labels:  promise
future.mapreduce
[EXPERIMENTAL] R package: future.mapreduce - Utility Functions for Future Map-Reduce API Packages
Stars: ✭ 12 (-36.84%)
Mutual labels:  futures

Eventually logo

Eventually

A Swift implementation of a Future, which can be used to model and transform asynchronous results while making it easy to bounce results between dispatch queues

Usage

Futures in Eventually can be used to wrap existing APIs, or to create new APIs using Futures

func operation(completion: (Int) -> Void) {
    DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) {
        completion(42)
    }
}

Future<Int> { resolve in
    operation { value
        resolve.success(value)
    }
}.then { result in
    switch result {
    case .success(let value):
        print("value is", value) // "value is 42"
    case .failure(let error):
        print("something went wrong:", error)
    }
}

When initializing a Future the closure receives a "resolver", this resolver is simply a closure that you will call with a FutureResult, a Result enum type which can be either .success or .failure.

There's also a couple of short-hand methods available

func calculateAge() -> Future<Int> {
    // ...
}
calculateAge().success { (value: Int) in
    print("Success value from calling calculateAge() is", value)
}.failure { error in
    print(The Future returned by calculateAge() gave us an error:", error)
}

A non-closure based API for resolving futures is also available

let future = Future<Int>()
future.success { value in
    ...
}
future.resolve(success: age)

Mapping values

With Eventually it is possible to map() one Future type to another, allowing us to compose and transform things easily

calculateAge().map({ (value: Int) -> String in
    return "Age is \(age)"
}).success { value in
    print(value) // "Age is 42"
}

Like always, chaining is possible so multiple transforms can be done

Evaluation Contexts

Most of the methods operating on a Future accepts an EvaluationContext that describes what GCD queue the operation should be called on

Future<String>(on: .background) { resolve
    // Performed on a background queue (eg `DispatchQueue.global(qos: .background)`)
    resolve.success("hello"))
}.map(on: .queue(someCustomQueue)) { value in
    // will be called on the supplied DispatchQueue (`someCustomQueue`)
    return value + " world"
}.map(on: .main) { value in
    // Mapping occurs on the main thread
    let label = UILabel()
    label.text = value
    return text
}.success { label in
    // default is the `.main` context
    self.view.addSubview(label)
}

Installation

Eventually is available as a CocoaPod (pod 'Eventually') and the Swift Package Manager. Framework installation is also available by dragging the Eventually.xcodeproj into your project or via Carthage.

Eventually has no dependencies outside of Foundation and Dispatch (GCD)

License

See the LICENSE file

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].