Skip to content

Commit

Permalink
Added a DartExecutor API for querying # of pending channel callbacks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adazh authored Jul 23, 2019
1 parent a0ec528 commit ef99738
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ public void send(@NonNull String channel, @Nullable ByteBuffer message, @Nullabl
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 -----

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public void handlePlatformMessageResponse(int replyId, @Nullable byte[] reply) {
}
}

/**
* 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;
Expand All @@ -141,4 +157,4 @@ public void reply(@Nullable ByteBuffer reply) {
}
}
}
}
}

0 comments on commit ef99738

Please sign in to comment.