1.0.1 • Published 7 years ago

xrtlibrary-id-manager v1.0.1

Weekly downloads
2
License
BSD-3-Clause
Repository
github
Last release
7 years ago

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)

  1. 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); });