mirror of
https://github.com/rilaxik/fivem-rpc.git
synced 2026-09-29 01:30:42 +00:00
feat(rpc): extract _pending* maps to Pending util
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Emitter } from '../utils/emitter'
|
||||
import { parse } from '../utils/funcs'
|
||||
import { Pending } from '../utils/pending'
|
||||
import {
|
||||
type RPCConfig,
|
||||
type RPCEnvironment,
|
||||
@@ -11,16 +12,28 @@ import {
|
||||
export class Wrapper {
|
||||
protected env: RPCEnvironment
|
||||
protected _emitterLocal: Emitter
|
||||
protected _pending: Pending
|
||||
protected debug: boolean
|
||||
protected console: Console
|
||||
|
||||
constructor(cfg: RPCConfig<RPCEnvironment>) {
|
||||
this.env = cfg.env
|
||||
this._emitterLocal = new Emitter()
|
||||
this._pending = new Pending(cfg.timeout ?? 5000)
|
||||
this.debug = cfg.debug ?? false
|
||||
this.console = console
|
||||
}
|
||||
|
||||
/** Settles the call waiting for this response; ignores late or unexpected ones */
|
||||
protected resolvePending(payload: RPCState): void {
|
||||
const found = this._pending.resolve(payload.uuid, payload.data?.[0])
|
||||
if (!found && this.debug) {
|
||||
this.console.log(
|
||||
`[RPC]:ignored response ${payload.event} ${payload.uuid} (no pending call, possibly timed out)`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
protected verifyEvent(state: Emitter, data: RPCStateRaw | RPCState) {
|
||||
const rpcData = typeof data === 'string' ? parse(data) : data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user