Created
December 4, 2017 23:44
-
-
Save hiranya911/b923b4c330eaf82ef33f23423671135f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.core.SettableApiFuture; | |
import com.google.firebase.tasks.TaskCompletionSource; | |
@Deprecated | |
public Task<String> incompleteTask() { | |
final TaskCompletionSource<String> source = new TaskCompletionSource<>(); | |
new Thread() { | |
@Override | |
public void run() { | |
try { | |
source.setResult(expensiveComputation()); | |
} catch (Exception e) { | |
source.setException(e); | |
} | |
} | |
}.start(); | |
return source.getTask(); | |
} | |
public ApiFuture<String> incompleteFuture() { | |
final SettableApiFuture<String> future = SettableApiFuture.create(); | |
new Thread() { | |
@Override | |
public void run() { | |
try { | |
future.set(expensiveComputation()); | |
} catch (Exception e) { | |
future.setException(e); | |
} | |
} | |
}.start(); | |
return future; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment