Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitSafely does not work as expected #51

Open
mplogas opened this issue Feb 10, 2015 · 4 comments
Open

waitSafely does not work as expected #51

mplogas opened this issue Feb 10, 2015 · 4 comments
Assignees

Comments

@mplogas
Copy link

mplogas commented Feb 10, 2015

So, I have a small DeferredAsyncTask

public DeferredAsyncTask<Void, Integer, WebCall> getRequestTask(WebCall webcall) {
        return new DeferredAsyncTask<Void, Integer, WebCall>() {
            @Override
            protected WebCall doInBackgroundSafe(Void... voids) throws Exception {
                 //do stuff
                return webcall;
            }
        };
    }

that is called in a small flow

try {
    DeferredAsyncTask<Void, Integer, WebCall> requestTask = http.getRequestTask(webCall);
    new AndroidDeferredManager().when(requestTask).done(new DoneCallback<WebCall>() {
        @Override
        public void onDone(WebCall result) {
            value.set(result.getResponsePayload());
            Log.i(Constants.LOG_TAG, "webcall - result " + result.getResponsePayload());
        }
    }).fail(new FailCallback<Throwable>() {
        @Override
        public void onFail(final Throwable tr) {
            Log.i(Constants.LOG_TAG, "webcall - " + tr.getMessage());
        }
    }).waitSafely();
} catch (Exception e) {
    e.printStackTrace();
}

When using waitSafely() it just hangs. Nothing is written to the logcat, program execution is halted. Implementation seem to be fine according to the documentation. Any ideas?

@saturnism
Copy link
Member

@mplogas which sdk version are you using?

@mplogas
Copy link
Author

mplogas commented Feb 11, 2015

Android: SDK 21, build tools 21.1.2
Java SDK: 1.8u25

@danielfaust
Copy link
Contributor

You're deadlocking the application by waiting on the UI thread, and this waiting prohibits the done or fail methods to get called on that thread. I just wonder why no ANR shows up. In essence you shouldn't be calling any wait method as your goal is to have completely asynchronous code. I think it's there for testing purposes.

@saturnism
Copy link
Member

eak yeah.. sorry it was there mostly for testing purposes and when the deferred tasks were executing on a different thread. waitSafely should probably be removed from AndroidDeferredManager, or warn that it shouldn't be used.

@saturnism saturnism added this to the 1.3 milestone Feb 27, 2016
@saturnism saturnism self-assigned this Feb 27, 2016
@saturnism saturnism removed this from the 1.3 milestone Oct 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants