1# ChangeLog 2##### 关键的接口/组件变更 3## 进程间通信子系统 4#### cl.rpc.1 sendRequest返回值类型变更 5 6##### 变更影响 7 8js的RemoteProxy和RemoteObject的sendRequest变更为异步接口,返回Promise,兑现值是SendRequestResult的实例。原有应用需要适配。 9 10##### 关键的接口/组件变更 11 12``` 13模块:ohos.rpc.IRemoteObject, ohos.rpc.RemoteProxy和ohos.rpc.RemoteObject 14接口:sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): boolean 15 16变更后接口: 17sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption): Promise<SendRequestResult> 18``` 19 20**适配指导** 21 22``` 23import rpc from "@ohos.rpc" 24import FA from "@ohos.ability.featureAbility"; 25 26let proxy; 27let connect = { 28 onConnect: function(elementName, remoteProxy) { 29 console.log("RpcClient: js onConnect called."); 30 proxy = remoteProxy; 31 }, 32 onDisconnect: function(elementName) { 33 console.log("RpcClient: onDisconnect"); 34 }, 35 onFailed: function() { 36 console.log("RpcClient: onFailed"); 37 } 38}; 39let want = { 40 "bundleName": "com.ohos.server", 41 "abilityName": "com.ohos.server.MainAbility", 42}; 43FA.connectAbility(want, connect); 44 45let option = new rpc.MessageOption() 46let data = rpc.MessageParcel.create() 47let reply = rpc.MessageParcel.create() 48proxy.sendRequest(1, data, reply, option) 49 .then(function(result) { 50 console.info("send request done") 51 if (result.errCode === 0) { 52 // read result from result.reply 53 } 54 }) 55 .catch(function(e) { 56 console.error("send request failed: " + e) 57 }) 58 .finally(() => { 59 data.reclaim() 60 reply.reclaim() 61 }) 62``` 63 64