xrtlibrary-id-manager
v1.0.1
Published
ID manager module of XRT library.
Downloads
2
Readme
Read Me
Introduction
This package implements an "ID Manager" that helps allocate ID to different entities and ensures no one's ID is the same as others. For example, in a server application, you may want to give ID to connections so that you can identify them, then you can use this package.
Installation
To install this package, type following command in your terminal:
npm install xrtlibrary-id-manager --save
And then, you can import this package in your NodeJS environment with following "require" statement.
var XRTLibIDMgr = require("xrtlibrary-id-manager");
API (Usage)
- IDManager:
Method: +------------------------+--------------------------+ | constructor([initial]) | Construct the manager. | | | | | | initial: The initial ID. | +------------------------+--------------------------+ | allocate() | Allocate an ID. | +------------------------+--------------------------+ | deallocate([id]) | Deallocate an ID. | | | | | | id: The ID. | +------------------------+--------------------------+
Example:
var mgr = new XRTLibIDMgr.IDManager(1); var ids = []; for (var i = 0; i < 10; ++i) { var id = mgr.allocate(); ids.push(id); } console.log(ids); ids.forEach(function(id) { mgr.deallocate(id); });