@gxchain2/utils
v0.0.1
Published
[![NPM Version](https://img.shields.io/npm/v/@gxchain2/utils)](https://www.npmjs.org/package/@gxchain2/utils) ![License](https://img.shields.io/npm/l/@gxchain2/utils)
Downloads
13
Readme
@gxchain2/utils
Utils include the following classes:
Channel
: Contains three implementsChannel
: An asynchronous queue, order by the order in which the elements are pushedHChannel
: An asynchronous queue, order by customizable heapPChannel
: An asynchronous queue, order by element index(grow from 0) and index must be continuous
Compress
: Provide some functions for compressing and decompressing dataFunctionalMap
andFunctionalSet
: Key customizable map and set
INSTALL
npm install @gxchain2/utils
USAGE
const channel = new Channel<string>();
channel.push('123');
channel.push('456');
setTimeout(() => {
channel.push('789');
}, 1000);
setTimeout(() => {
channel.push('101112');
}, 2000);
setTimeout(() => {
channel.abort();
}, 3000);
(async () => {
for await (const data of channel.generator()) {
console.log('data:', data);
}
console.log('channel end');
})();
const bufferMap = new FunctionalMap<Buffer, string>((a: Buffer, b: Buffer) => a.compare(b));
bufferMap.set(Buffer.from('aaaaaa', 'hex'), 'aaaaaa');
console.log(bufferMap.get(Buffer.from('aaaaaa', 'hex')) === 'aaaaaa'); // true