-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for await function #10
Comments
It's a mistake with non labeled parameters 👎 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 // 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")
}) |
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 // 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
}
} |
I'm trying to use
await
using the syntax from the readme.The
getCityPromise
function is declared like this:But the compiler raises an error
Then I looked at the unit tests, and I saw that a special operator
..
is used instead of calling theawait
function.Using that operator my code doesn't raise any error anymore. Should the documentation be fixed or I'm missing something?
The text was updated successfully, but these errors were encountered: