Skip to content

Instantly share code, notes, and snippets.

@fkmhrk
Created October 1, 2014 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fkmhrk/020a423dce8bb117403e to your computer and use it in GitHub Desktop.
Save fkmhrk/020a423dce8bb117403e to your computer and use it in GitHub Desktop.
BlockingTask
abstract class BlockingTask<T> {
private boolean mDone;
private T mResult;
private Exception mException;
public void execute() {
mDone = false;
doAsyncCall();
while (!mDone) {
try { Thread.sleep(300); } catch (Exception e) { }
}
}
protected void notifyResult(T result) {
mResult = result;
mException = null;
mDone = true;
}
protected void notifyError(Exception e) {
mResult = null;
mException = e;
mDone = true;
}
abstract protected void doAsyncCall();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment