npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xlock

v1.0.1

Published

Lock For NodeJS.

Downloads

4

Readme

xlock

a easy and useful lock for NodeJS

npm

How to Install?

npm install xlock

How to Use?

Import it and use it, like this

import xlock = require("xlock");
async function TestLock()
{
    // Lock
    await xlock.lock("test");
    DoSomething();
    // Unlock. NOTICE, ONE LOCK ONE UNLOCK, it must be match!
    xlock.unlock("test");
}

API

/**
 * Wait a moment.
 * @param ms wait time. microsecond.
 */
async function wait(ms: number);
/**
 * Sleep a moment. Same as wait.
 * @param ms sleep time. microsecond.
 */
async function sleep(ms: number);
/**
 * Until test() return a true, otherwise wait.
 * @param test test function.
 */
async function until(test: ()=>boolean): Promise<boolean>;
/**
 * Lock
 * @param lock Lock Name
 * @param timeout Time. some time pass, if not get lock, it will be timeout and return false. default timeout disable.
 * @param mode Lock Mode. (Normal, Read, Write)
 */
async function lock(name:string, timeout?:number, mode?: Mode):Promise<boolean>
/**
 * Unlock
 * @param name Unlock Name
 */
function unlock(name: string): void;
/**
 * Check Lock. If unlock, return false. If lock, return true.
 * @param name Lock name
 * @param mode Lock Mode. (Normal, Read, Write)
 */
function check(name: string, mode?:Mode): boolean;
/**
 * Read Lock
 * @param name Lock Name
 * @param timeout see lock api
 */
async function read_lock(name:string, timeout?:number):Promise<boolean>;
/**
 * Read Unlock
 * @param name Unlock Name
 */
function read_unlock(name: string): void;
/**
 * Check ReadLock
 * @param name Lock Name
 */
function check_read_lock(name:string): boolean;
/**
 * Write Lock
 * @param name Lock Name
 * @param timeout see lock api
 */
async function write_lock(name:string, timeout?:number):Promise<boolean>;
/**
 * Write Unlock
 * @param name Unlock Name
 */
function write_unlock(name: string): void;
/**
 * Check WriteLock
 * @param name Lock Name
 */
function check_write_lock(name:string): boolean;

async function Lock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;
async function ReadLock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;
async function WriteLock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;

Sample

In /test dir, you will find sample and test.

Thank you for using. Enjoy it!

xlock

一个简单有用的锁

npm

如何安装?

npm install xlock

如何使用?

引用它并使用它, 像这样

import xlock = require("xlock");
async function TestLock()
{
    // 锁
    await xlock.lock("test");
    DoSomething();
    // 解锁. 注意,一次锁,一次解锁,必须匹配。
    xlock.unlock("test");
}

API

/**
 * 等待一段时间。
 * @param ms 等待时间。毫秒。
 */
async function wait(ms: number);
/**
 * 睡眠一段时间。与wait功能相同。
 * @param ms 睡眠时间. 毫秒.
 */
async function sleep(ms: number);
/**
 * 持续等待,直到test()返回true
 * @param test 测试函数.
 */
async function until(test: ()=>boolean): Promise<boolean>;
/**
 * 锁
 * @param lock 锁名
 * @param timeout 超时时间. 经过设置的时间,如果仍然无法获取锁,则超时并返回false。默认超时未禁用
 * @param mode 锁模式。 (Normal 普通互斥锁, Read 读锁, Write 写锁)
 */
async function lock(name:string, timeout?:number, mode?: Mode):Promise<boolean>
/**
 * 解锁
 * @param name 解锁的锁名
 */
function unlock(name: string): void;
/**
 * 检查锁状态,如果上锁,返回true。如果未上锁,返回false。
 * @param name 锁名
 * @param mode 锁模式。 (Normal 普通互斥锁, Read 读锁, Write 写锁)
 */
function check(name: string, mode?:Mode): boolean;
/**
 * 读锁
 * @param name 锁名
 * @param timeout 参看lock
 */
async function read_lock(name:string, timeout?:number):Promise<boolean>;
/**
 * 读锁解锁
 * @param name 解锁的锁名
 */
function read_unlock(name: string): void;
/**
 * 检测读锁状态
 * @param name 锁名
 */
function check_read_lock(name:string): boolean;
/**
 * 写锁
 * @param name 锁名
 * @param timeout 参看lock
 */
async function write_lock(name:string, timeout?:number):Promise<boolean>;
/**
 * 写锁解锁
 * @param name 解锁的锁名
 */
function write_unlock(name: string): void;
/**
 * 检测写锁状态
 * @param name 锁名
 */
function check_write_lock(name:string): boolean;

async function Lock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;
async function ReadLock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;
async function WriteLock(name: string, dofunc: ()=>void, timeout?:number, mode?: Mode):Promise<boolean>;

例子

在test文件夹下,你可以找到例子。

感谢使用。希望你们喜欢!