Comments (2)
It's a mistake with non labeled parameters 👎
I've solved it in b2323a9 and it will be released with 0.9.2.
Due to the fact we can't provide a behaviour like in C#, in order to avoid block of the current thread (ie. the main thread) I suggest you to do await
operations in another queue by adding it inside an async
closure.
That's the example fixed inside the README:
// With `async` we have just defined a Promise which will be executed in a given
// context (if omitted `background` thread is used) and return an Int value.
let asyncFunc = async({ _ -> Int // you must specify the return of the Promise, here an Int
// With `await` the async code is resolved in a sync manner
let loggedUser = try await(loginUser(username,pass))
// one promise...
let followersList = try await(getFollowers(loggedUser))
// after another...
let countUnfollowed = try await(unfollow(followersList))
// ... linearly
// Then our async promise will be resolved with the end value
return countUnfollowed
}).then({ value in // ... and, like a promise, the value is returned
print("Unfollowed \(value) users")
})
from hydra.
This is how the operator are defined:
With .. the call is allowed to throws in case of Promise's failure.
/// This define a `..` operator you can use instead of calling `await` func.
/// If you use this operator you need to also use `do/catch` in order to catch exception for rejected promises.
prefix operator ..
public prefix func ..<T> (_ promise: Promise<T>) throws -> T {
return try awaitContext.await(promise)
}
While using ..!
if it fails it will return nil.
// This define a `..!` operator you can use instead of calling `await`.
// Using this operator if promise is rejected for any reason the result is `nil` and no throws is called.
prefix operator ..!
public prefix func ..!<T> (_ promise: Promise<T>) -> T? {
do {
return try awaitContext.await(promise)
} catch {
return nil
}
}
from hydra.
Related Issues (20)
- How to put a Promise into always?
- Is Unit Test possible? Or how do you use it? HOT 1
- Write twice "retry" in README
- Cancellable Promise in a Chain
- Progress block
- Ubuntu compilation error HOT 3
- Crash on operation: PromiseStatus on iOS but not on macOS HOT 2
- Adding support for delay parameter in retry operator HOT 1
- How to use Promise<Void> in Swift 5.2 HOT 1
- Build fail on Xcode 12 beta 2 HOT 1
- Multiple then are not passed correctly in Xcode 12/Swift 5.3
- Compilation under Linux environment does not work
- Compatibility with Xcode 12, fixed warning and update project settings
- Since adding `[weak self]` in Promise+Recover with version 2.0.4 the promise lose the reference HOT 3
- Retry vs Delay
- Deprecation of `await` keyword in Swift 5.4+. Using new Hydra.await() HOT 1
- Hydra compile issues in Xcode 13 HOT 1
- Is the minimum requirement still iOS 9?
- Importing Hydra in a file where there is a UIViewControllerRepresentable gives compilation errors
- Method is ambiguous for type lookup in this context
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hydra.