Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
synchronous-fsm
Advanced tools
A synchronous FSM that also triggers events when entering or leaving a state.
npm install synchronous-fsm
Require synchronous-fsm:
var FSM = require("synchronous-fsm");
To initialize the synchronous we need to define states and transitions first:
var states = {
// It has an 'opened' state
"opened": [
// That accepts a 'pass' event that will execute the 'pass' action
["pass", function onPass(event) {
passCalled = event;
// And when done, it will transit to the 'closed' state
}, "closed"],
// It also has a 'action' event that doesn't trigger a transition
["coin", function onCoin(event) {
console.log("thanks");
}]
],
// It also has a 'closed' state
"closed": [
// That accepts a 'coin' event that will execute the 'coin' action
["coin", function coin(event) {
coinCalled = event;
// And when done, it will transit back to the 'opened' state
}, "opened"]
]
};
Then we can initialize the state machine in the desired state:
// Initialize in the "opened" state
var fsm = new FSM("opened", states);
Trigger a transition:
// Will transit to "closed", executing the onPass handler
fsm.event("pass");
// Could also transit with some data that will be received by the handler
fsm.event("pass", "6km/h", "8:30pm");
Get the current state:
fsm.getCurrent(); // opened
Can also be directly advanced to a given state:
fsm.advance("closed"); // will move the state machine to this state
The stateMachine also triggers an "entry" and an "exit" event when entering and leaving a state. Simply add the handlers like for any other event:
var states = {
// It has an 'opened' state
"opened": [
...
// This handler will be called when entering the state
["entry", function onEntry(event) {
console.log("entering state...");
}],
// This handler will be called when leaving the state
["exit", function onExit(event) {
console.log("leaving state...");
}],
],
// It also has a 'closed' state
"closed": [
...
]
};
MIT
FAQs
A synchronous FSM that triggers events when entering or leaving a state
The npm package synchronous-fsm receives a total of 1 weekly downloads. As such, synchronous-fsm popularity was classified as not popular.
We found that synchronous-fsm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.