Added a DartExecutor API for querying # of pending channel callbacks (flutter/engine#10021)

This commit is contained in:
adazh
2019-07-23 13:11:03 -07:00
committed by GitHub
parent c39c231938
commit 6f7e34fbb8
2 changed files with 37 additions and 1 deletions

View File

@@ -196,6 +196,26 @@ public class DartExecutor implements BinaryMessenger {
public void setMessageHandler(@NonNull String channel, @Nullable BinaryMessenger.BinaryMessageHandler handler) {
messenger.setMessageHandler(channel, handler);
}
/**
* Returns the number of pending channel callback replies.
*
* <p>When sending messages to the Flutter application using {@link BinaryMessenger#send(String,
* ByteBuffer, io.flutter.plugin.common.BinaryMessenger.BinaryReply)}, developers can optionally
* specify a reply callback if they expect a reply from the Flutter application.
*
* <p>This method tracks all the pending callbacks that are waiting for response, and is supposed
* to be called from the main thread (as other methods). Calling from a different thread could
* possibly capture an indeterministic internal state, so don't do it.
*
* <p>Currently, it's mainly useful for a testing framework like Espresso to determine whether all
* the async channel callbacks are handled and the app is idle.
*/
@UiThread
public int getPendingChannelResponseCount() {
return messenger.getPendingChannelResponseCount();
}
//------ END BinaryMessenger -----
/**

View File

@@ -118,6 +118,22 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
}
}
/**
* Returns the number of pending channel callback replies.
*
* <p>When sending messages to the Flutter application using {@link BinaryMessenger#send(String,
* ByteBuffer, io.flutter.plugin.common.BinaryMessenger.BinaryReply)}, developers can optionally
* specify a reply callback if they expect a reply from the Flutter application.
*
* <p>This method tracks all the pending callbacks that are waiting for response, and is supposed
* to be called from the main thread (as other methods). Calling from a different thread could
* possibly capture an indeterministic internal state, so don't do it.
*/
@UiThread
public int getPendingChannelResponseCount() {
return pendingReplies.size();
}
private static class Reply implements BinaryMessenger.BinaryReply {
@NonNull
private final FlutterJNI flutterJNI;
@@ -141,4 +157,4 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
}
}
}
}
}