RPC fixes
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
ci/woodpecker/tag/ociImageTag Pipeline was successful
Details
This commit is contained in:
parent
53149858e9
commit
58266bcb7f
|
@ -13,7 +13,7 @@ let serial: bigint = BigInt(0);
|
|||
const logger = new Logger("RpcLog");
|
||||
|
||||
function getRpcClient(): Socket {
|
||||
if (client) {
|
||||
if (client != null) {
|
||||
return client;
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,9 @@ function getRpcClient(): Socket {
|
|||
}
|
||||
|
||||
async function rpcCall<D, T>(method: string, data: D): Promise<T> {
|
||||
const currentSerial = serial;
|
||||
serial = serial + BigInt(1);
|
||||
|
||||
const header = new Uint8Array([77]);
|
||||
const textEncoder = new TextEncoder();
|
||||
const methodBuf = textEncoder.encode(method);
|
||||
|
@ -99,7 +102,7 @@ async function rpcCall<D, T>(method: string, data: D): Promise<T> {
|
|||
packetBuf.set(dataBuf, header.length + serialLength + sizeLength + methodBuf.length + sizeLength);
|
||||
|
||||
const packetDataView = new DataView(packetBuf.buffer);
|
||||
packetDataView.setBigUint64(header.length, serial);
|
||||
packetDataView.setBigUint64(header.length, currentSerial);
|
||||
packetDataView.setUint32(header.length + serialLength, methodBuf.length);
|
||||
packetDataView.setUint32(header.length + serialLength + sizeLength + methodBuf.length, dataBuf.length);
|
||||
|
||||
|
@ -107,13 +110,11 @@ async function rpcCall<D, T>(method: string, data: D): Promise<T> {
|
|||
client.write(packetBuf);
|
||||
|
||||
const fut = new Promise((resolve, reject) => {
|
||||
client.once(`mag-data:${serial}`, resolve);
|
||||
client.once(`mag-data:${currentSerial}`, resolve);
|
||||
client.once("close", reject);
|
||||
client.once("error", reject);
|
||||
});
|
||||
|
||||
serial++;
|
||||
|
||||
const result = await fut as { success: false, data: any } | { success: true, data: T };
|
||||
|
||||
if (!result.success) {
|
||||
|
|
Loading…
Reference in New Issue