xx

Object Locking for JavaScript: It's what you need when you need it, but you have to wait in line to get it.

Showing:

Popularity

Downloads/wk

14

GitHub Stars

4

Maintenance

Last Commit

9yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.2KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

xx: Object Locking for JavaScript

It's what you need when you need it, but you have to wait in line to get it.

xx simplifies the synchronization of data objects between concurrent tasks.

Installation

  • Node.JS: npm install xx
  • Browsers: Add lib/xx.js to your HTML page.

Intro

Here's a brief example that shows how to use xx:

var xx = require('xx'); // import xx

var config = {}; // Have some data to guard

config.xx = xx(); // Create a lock object

// Acquire lock on the object with an async callback:
config.xx(
    function() {
        // Invoked when the object is available

        // Call without a function when you want to unlock the object:
        config.xx();
    }.bind(this)
);

Usage with Async Libraries

Here's a brief example that shows how it can be used with an async library (such as ff):

var xx = require('xx'); // import xx
var ff = require('ff'); // Use ff for a demo

var config = {
    fileA: "A.txt",
    fileB: "B.txt"
}; // Have some data to guard

config.xx = xx(); // Create a lock object

var f = ff(this, function () {

    // Added: Wait to acquire lock
    config.xx(f());

}, function () {
    fs.readFile(config.fileA, f());
    fs.readFile(config.fileB, f());
}, function (fileA, fileB) {
    concatFiles(fileA, fileB, f());
}, function (result) {
    config.result = result.toUpperCase();

    // Added: Done with lock here!
    config.xx();

    f();
}).cb(cb);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100