action-flow
v2.3.0
Published
Smart mutex manager.
Downloads
7
Readme
Action flow 2.3
Smart mutex manager.
Example
You can pause the user's requests until the user's previous request is executed.
How it works?
1) Connect and configure the action-flow
// commonJS
const AF = require('action-flow').default(options);
// es modules
import AFCreator from 'action-flow';
const AF = AFCreator(options);
2) Describe the operation. Any objects will accepted to describing.
const userRequestFlow = AF.create({
description: 'user-request',
userId,
});
Or you can create a common thread for any threads.
const anyFlow = AF.multi([
{one: 1}, {two: 2},
]);
This way, only one client can executing these two operations at a time.
The thread of two operations will not start until these two threads of these operations are free. The expectation of a stream occurs sequentially to avoid deadlocks.
3) Set the waiting the operation.
await userRequestFlow.await();
4) Do your code.
// execute user request code
5) Set the ending the operation.
await userRequestFlow.end();
Drivers & Custom drivers
At now the action-flow have 3 drivers. To use specific driver, use driverName option.
- redis (default)
- process
- mongodb (just-mongo library is dev dependency, install that to use)
About each of drivers
redis
Queue storage in Redis lists.
Options (optional): host, port, password.
const AF = require('action-flow')({
host: 'localhost',
password: 'yourPwd',
});
process
Storage in Node.js process memory. No specific options.
const AF = require('action-flow')({
driverName: 'process',
});
mongodb
MongoDB storage.
Options (optional): user, password, host, port.
const AF = require('action-flow')({
host: 'localhost',
});
Use driverClass option to connect custom driver.
const AF = require('action-flow')({
driverName: 'custom',
driverClass: someClass,
});
More options
| Name | Description | Required | Default | |----------------- |---------------------- |:--------: |:-------: | | awaitTimeoutSec | Maximum waiting time | false | 60 | | sessionName | Prefix for all descriptions | false | null | | noSHA | Turn off sha256 for description | false | false |