1
0
Fork 0

Create NexusDataQueue class for storing a queue of items to be sent

This commit is contained in:
Krzysztof Sikorski 2021-11-11 21:20:22 +01:00
parent 0da09d9efb
commit 49ab3a4d6e
Signed by: krzysztof-sikorski
GPG Key ID: 4EB564BD08FE8476
1 changed files with 36 additions and 0 deletions

36
src/nexusDataQueue.js Normal file
View File

@ -0,0 +1,36 @@
/* exported NexusDataQueue */
/* global NexusData */
'use strict'
class NexusDataQueue {
constructor() {
this._data = new Map()
this._currentRequestId = null
}
push(nexusData) {
if (!(nexusData instanceof NexusData)) {
window.console.error('[NexusDataQueue] push: argument is not an instance of NexusData!')
}
nexusData.previousRequestId = this._currentRequestId
this._currentRequestId = nexusData.requestId
this._data.set(nexusData.requestId, nexusData)
}
get(requestId) {
if (this._data.has(requestId)) {
return this._data.get(requestId)
}
return null
}
has(requestId) {
return this._data.has(requestId)
}
delete(requestId) {
if (this._data.has(requestId)) {
this._data.delete(requestId)
}
}
}