Example usage for android.os ConditionVariable block

List of usage examples for android.os ConditionVariable block

Introduction

In this page you can find the example usage for android.os ConditionVariable block.

Prototype

public boolean block(long timeout) 

Source Link

Document

Block the current thread until the condition is opened or until timeout milliseconds have passed.

Usage

From source file:com.facebook.FacebookActivityTestCase.java

protected void runOnBlockerThread(final Runnable runnable, boolean waitForCompletion) {
    Runnable runnableToPost = runnable;
    final ConditionVariable condition = waitForCompletion ? new ConditionVariable(!waitForCompletion) : null;

    if (waitForCompletion) {
        runnableToPost = new Runnable() {
            @Override/*from  w w w. j  av a2  s  .c  o  m*/
            public void run() {
                runnable.run();
                condition.open();
            }
        };
    }

    TestBlocker blocker = getTestBlocker();
    Handler handler = blocker.getHandler();
    handler.post(runnableToPost);

    if (waitForCompletion) {
        boolean success = condition.block(10000);
        assertTrue(success);
    }
}