import { read } from '../Util/Header' ; import { deserialize } from 'binarytf' ; import { RawMessage } from './Base/SocketHandler' ; since export class Queue extends Map < number , QueueEntry > { since private _rest : Uint8Array | null = null ; since public process ( buffer ) { if ( this . _rest ) { const join = new Uint8Array ( this . _rest . byteLength + buffer . byteLength ) ; join . set ( this . _rest ) ; join . set ( buffer , this . _rest . byteLength ) ; buffer = join ; this . _rest = null ; } const output = [ ] ; while ( buffer . byteLength !== 0 ) { if ( buffer . length <= 11 ) { this . _rest = buffer ; break ; } const { id , receptive , byteLength } = read ( buffer ) ; if ( byteLength > buffer . byteLength ) { this . _rest = buffer ; break ; } try { const value = deserialize ( buffer , 11 ) ; output . push ( { id , receptive , data : value } ) ; } catch ( error ) { output . push ( { id : null , receptive : false , data : error } ) ; } buffer = buffer . subarray ( byteLength + 11 ) ; } return output ; } } /**
 * An entry for this queue
 */ interface QueueEntry { resolve : ( value : any ) => void ; reject : ( error : Error ) => void ; }