File Explorer

/var/runtime/node_modules/@aws-sdk/node_modules/mqtt/lib

This explorer reads the filesystem of the server it runs on, so /workspace/user isn't present here. Browsing and the terminal still work against this server's own disk from /.

1 dir
7 files
unique-message-id-provider.js1.5 KB · 66 lines
'use strict' const NumberAllocator = require('number-allocator').NumberAllocator /** * UniqueMessageAllocator constructor * @constructor */function UniqueMessageIdProvider () {  if (!(this instanceof UniqueMessageIdProvider)) {    return new UniqueMessageIdProvider()  }   this.numberAllocator = new NumberAllocator(1, 65535)} /** * allocate * * Get the next messageId. * @return if messageId is fully allocated then return null, *         otherwise return the smallest usable unsigned int messageId. */UniqueMessageIdProvider.prototype.allocate = function () {  this.lastId = this.numberAllocator.alloc()  return this.lastId} /** * getLastAllocated * Get the last allocated messageId. * @return unsigned int */UniqueMessageIdProvider.prototype.getLastAllocated = function () {  return this.lastId} /** * register * Register messageId. If success return true, otherwise return false. * @param { unsigned int } - messageId to register, * @return boolean */UniqueMessageIdProvider.prototype.register = function (messageId) {  return this.numberAllocator.use(messageId)} /** * deallocate * Deallocate messageId. * @param { unsigned int } - messageId to deallocate, */UniqueMessageIdProvider.prototype.deallocate = function (messageId) {  this.numberAllocator.free(messageId)} /** * clear * Deallocate all messageIds. */UniqueMessageIdProvider.prototype.clear = function () {  this.numberAllocator.clear()} module.exports = UniqueMessageIdProvider