mirror of
https://github.com/rilaxik/fivem-rpc.git
synced 2026-09-28 01:29:13 +00:00
feat(rpc): extract _pending* maps to Pending util
This commit is contained in:
+12
-2
@@ -144,7 +144,7 @@ export class RPCInstanceWebview extends Wrapper {
|
||||
type: 'event',
|
||||
}
|
||||
|
||||
return await this._createHttpClientRequest<Awaited<Response>>(payload)
|
||||
return this._request<Awaited<Response>>(payload)
|
||||
}
|
||||
|
||||
// ===== SERVER =====
|
||||
@@ -196,7 +196,7 @@ export class RPCInstanceWebview extends Wrapper {
|
||||
type: 'event',
|
||||
}
|
||||
|
||||
return await this._createHttpClientRequest<Awaited<Response>>(payload)
|
||||
return this._request<Awaited<Response>>(payload)
|
||||
}
|
||||
|
||||
// ===== SELF =====
|
||||
@@ -264,6 +264,16 @@ export class RPCInstanceWebview extends Wrapper {
|
||||
|
||||
// ===== UTILS =====
|
||||
|
||||
/** Sends an event to the client and waits for its response (with timeout) */
|
||||
private _request<R>(payload: RPCState): Promise<R> {
|
||||
const response = this._pending.wait<R>(payload.uuid)
|
||||
this._createHttpClientRequest(payload).then(
|
||||
data => this._pending.resolve(payload.uuid, data),
|
||||
(error: Error) => this._pending.reject(payload.uuid, error),
|
||||
)
|
||||
return response
|
||||
}
|
||||
|
||||
private async _createHttpClientRequest<R>(
|
||||
data: RPCStateRaw | RPCState,
|
||||
): Promise<R> {
|
||||
|
||||
Reference in New Issue
Block a user