synchronousresultreceiver的解析以及使用-爱代码爱编程
使用:
packages/modules/Bluetooth/service/java/com/android/server/bluetooth/BluetoothManagerService.java
@GuardedBy("mBluetoothLock")
private String synchronousGetName(AttributionSource attributionSource)
throws RemoteException, TimeoutException {
if (mBluetooth == null) return null;
final SynchronousResultReceiver<String> recv = SynchronousResultReceiver.get();
mBluetooth.getName(attributionSource, recv);
return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
}
流程:
其内部有一个 CompletableFuture 变量 。
1
SynchronousResultReceiver.get() 从其内部对象池中得到一个 SynchronousResultReceiver对象 。
2
awaitResultNoInterrupt 调用 CompletableFuture 的 get 方法 。
等待 CompletableFuture 完成,也就是等待其他地方调用 CompletableFuture的 complete方法 。
3
send 方法调用CompletableFuture的 complete方法 。