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

@infect/rda-lock-client

v3.2.5

Published

Client for the RDA Lock Service

Downloads

10

Readme

RDA Lock Client

Client for the RDA Lock Service. Lets you get atomic locks on resources and wait for locks that are currently busy.

API

An instance of a Lock which is returned by the factor method createLock can be used for locking one resource once. It has a strict lifecycle which makes sure that no resource can be locked twice over all of the RDA services.

import LockClient from '@infect/rda-lock-client';

// create a client that can talk to the service
const client = new LockClient({
    serviceRegistryHost: 'http://localhost:9000'
});

// get a lock for a resource
const lock = client.createLock('my-resource')

// wait until the lock could be created
await lock.lock();

// do your stuff on the resource you just locked
console.log('working hard!');

// free the lock, let others work on the resource
await lock.free();

LockClient.constructor

Sets up a lock client. Needs some way to access the service registry in order to be able to contact the lock service. You need to either pass the registry host or an instance of a registry client

// create a client that can talk to the service
const client = new LockClient({
    serviceRegistryHost: 'http://localhost:9000',
    registryClient,
});

LockClient.createLock

Factory method creating a new instance of the Lock class which represents one locking cycle for one resource. Needs a resource id to lock and takes optionally some options:

  • ttl: defines how long the lock persists if the lock client stops refreshing the locks (seconds)
  • timeout: how long to wait until a lock can be established (seconds)
  • keepAlie: boolean defining if the client should keep alive the lock in order to not run into the ttl

Returns an instance of the Lock class.

const lock = client.createLock('cluster::67262', {
    timeout: 60,
    ttl: 10,
    keepAlive: false,
});

async Lock.lock()

Lock the resource specified in the call to the LockClient.createLock method. wait until the lock could be acquired or the timeout is reached. Locking may not be possible because other lock instances occupy the resource already.

throws an error when the timeout is reached.

await lock.lock();

async Lock.free()

Free the resource again, let others create a lock on it.

await lock.free();

LockClient.adoptLock

Adopt a already created lock, lets you cancel or free it. Be aware that this method doesn't validate the status or existence of the lock, so you may run into interesting problems. The client just assumes that the lock has the status acquired.

ATTENTION: the original lock needs to have the keepAlive option disabled!

Needs a lock id to lock and takes optionally some options:

  • ttl: defines how long the lock persists if the lock client stops refreshing the locks (seconds)
  • timeout: how long to wait until a lock can be established (seconds)
  • keepAlie: boolean defining if the client should keep alive the lock in order to not run into the ttl

Returns an instance of the Lock class.

const lock = client.adoptLock(634265, {
    timeout: 60,
    ttl: 10,
    keepAlive: false,
});

Lock.getId()

Returns the id of a acquired lock.

const lockId = lock.getId();

Lock.isAcquired()

Tessl you if the lock wa acquired. Does not indicate if it was freed already.

const lockId = lock.isAcquired();