Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Created December 4, 2017 23:44
Show Gist options
  • Save hiranya911/b923b4c330eaf82ef33f23423671135f to your computer and use it in GitHub Desktop.
Save hiranya911/b923b4c330eaf82ef33f23423671135f to your computer and use it in GitHub Desktop.
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