# Combine: Wrapped async call with Future, but Future.sink doesn't appear to complete

**URL:** <https://forums.swift.org/t/combine-wrapped-async-call-with-future-but-future-sink-doesnt-appear-to-complete/39953>\
**Category:** Core Libraries\
**Tags:** future, swiftui, combine, firebase\
**Created:** [September 2, 2020, 1:28pm UTC](https://forums.swift.org/t/combine-wrapped-async-call-with-future-but-future-sink-doesnt-appear-to-complete/39953 "2020-09-02T13:28:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeromeInTheHouse](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jeromeInTheHouse](https://forums.swift.org/u/jeromeInTheHouse)\
**Post date:** [September 2, 2020, 1:28pm UTC](https://forums.swift.org/t/combine-wrapped-async-call-with-future-but-future-sink-doesnt-appear-to-complete/39953/1 "2020-09-02T13:28:46Z")

</div>

First-time poster, long-time reader ... I've wrapped an async call to the Firebase Authorization API. I'm calling it from inside a SwiftUI View function.  
`
func authenticateFirebaseEmail(email: String, password: String) -> Future<String, Error> {
return Future<String,Error> { promise in
Auth.auth().signIn(withEmail: email, password: password) { result, error in
if let error=error {
print("failure detected")
promise(.failure(error))
}`

`
```
        if let result=result {
            print("result detected - returning success promise")
            promise(.success(result.user.email!))
        }
        
    }
}

```
}
...
`

`func logMeInFuncInView() {
var cancellable : AnyCancellable?
cancellable = authenticateFirebaseEmail(email: self.userEmail, password: self.password).map( {
value in return value
})
.sink(receiveCompletion: { (completion) in
print("completion received")
}, receiveValue: { user in
print("value received")
self.errorMessage = user
})
}
`

The console output is as follows, but never reaches the "completion received" or "value received" calls:  
`
result detected - returning successful promise
`

Is the issue with the wrapped callback, the future, the way I'm using the future, or something that I'm not seeing entirely?

---

<div class="post-metadata">

**Author:** ![sharplet](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sharplet/32/6184_2.png) [@sharplet](https://forums.swift.org/u/sharplet)\
**Post date:** [September 2, 2020, 1:38pm UTC](https://forums.swift.org/t/combine-wrapped-async-call-with-future-but-future-sink-doesnt-appear-to-complete/39953/2 "2020-09-02T13:38:45Z")

</div>

If you chain the `.print()` operator onto your future before `.sink`, you should see that the future is being cancelled before the value/completion is ever received. The returned `AnyCancellable` needs to be retained somewhere for the lifetime of the future. Because it's local to `logMeInFuncInView()`, it's being cancelled the moment the function returns.

---

<div class="post-metadata">

**Author:** ![jeromeInTheHouse](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jeromeInTheHouse](https://forums.swift.org/u/jeromeInTheHouse)\
**Post date:** [September 2, 2020, 2:40pm UTC](https://forums.swift.org/t/combine-wrapped-async-call-with-future-but-future-sink-doesnt-appear-to-complete/39953/3 "2020-09-02T14:40:32Z")

</div>

Thank you! Yeah, I see it now. Guess I gotta figure out how to get that `AnyCancellable` into a mutable variable.
