google / promises

Promises is a modern framework that provides a synchronization construct for Swift and Objective-C.
Apache License 2.0
3.81k stars 295 forks source link

Can't use fulfill with Promise<Void> #79

Closed bes closed 5 years ago

bes commented 5 years ago

Hi,

I can't figure out how to use fulfill with a Promise<Void>.

func doSomethingInBackground() -> Promise<Void> {
    return Promise<Void>(on: bgQueue) {
        fulfill, reject in
        myMoc.perform {
            fulfill() // compiler complains Missing argument for parameter #1 in call
        }
    }
}

fulfill(nil) doesn't work either.

What is your recommendation on how to initialize an async Promise which does not have a logical return value?

ghost commented 5 years ago

@bes try

func doSomethingInBackground() -> Promise<Void> {
    return Promise<Void>(on: bgQueue) {
        fulfill, reject in
        myMoc.perform {
             fulfill(())
        }
    }
}

from Swift -> Misc: public typealias Void = ()

but I don't know why fulfill(Void) don't work

bes commented 5 years ago

@umbri Thanks, it worked! I tried fulfill(Void) before, but as you said it does not seem to work. But fulfill(()) works.