Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
storage-based-queue
Advanced tools
Simple client queue mechanism. Create it and run asynchronously with worker class in browser.
Storage based queue processing mechanism. Today, many backend technology is a simple derivative of the queuing systems used in the browser environment.
You can run jobs over the channels as asynchronous that saved regularly.
This library just a solution method for some use cases. Today, there are different technologies that fulfill the similar process.
Reminders:
Data regularly store (localstorage, inmemory or custom storage drivers) added to queue pool. Storing queue data is also inspired by the JSON-RPC method. When the queue is started, the queues start to be processed sequentially in the specified range according to the sorting algorithm.
If any exceptions occur while the worker classes are processing, the current queue is reprocessed to try again. The task is frozen when it reaches the defined retry value.
You need to create at least one channel. One channel can be created as many channels as desired. Channels run independently of each other. The areas where each channel will store tasks are also separate. The area where tasks are stored is named with the channel name and prefix.
The important thing to remember here is that each newly created channel is actually a new copy of the Queue class. So a new instance is formed, but the dependencies of the channels are still alive as singletons.
Example; You created two channels. Their names are channelA and channelB. If you make a setting in the channelA instance, this change will also be reflected in channelB and all other channels.
You can create countless worker. Worker classes should return boolean
(true / false)
data with the Promise class as the return value. The return Promise / resolve (true)
must be true if a task is successfully completed and you want to pass the next task. A possible exception should also be tried again: Promise / resolve (false)
. If we do not want the task to be retried and we want to pass the next task: Promise / reject ('any value')
Also you can use native browser worker. If you are browser does not support Worker, Browser Worker polyfil will add a pseudo-worker function to window object.
Plase check the docs: Workers
$ npm install storage-based-queue --save
import:
import Queue from "storage-based-queue";
Script Tag:
<script src="https://unpkg.com/storage-based-queue@1.2.2/dist/queue.min.js" />
Worker class:
class MessageSenderWorker {
handle(message) {
// If return value is false, this task will retry until retry value 5.
// If retry value is 5 in worker, current task will be as failed and freezed in the task pool.
retry = 5;
// Should return true or false value (boolean) that end of the all process
// If process rejected, current task will be removed from task pool in worker.
return new Promise((resolve, reject) => {
// A function is called in this example.
// The async operation is started by resolving the promise class with the return value.
const result = someMessageSenderFunc(message);
if (result) {
// Task will be completed successfully
resolve(true);
} else {
// Task will be failed.
// If retry value i not equal to 5,
// If the retry value was not 5, it is being sent back to the pool to try again.
resolve(false);
}
});
}
}
Register worker:
Queue.workers({ MessageSenderWorker });
Create channel:
// create new queue instance with default config
const queue = new Queue();
// create a new channel
const channel = queue.create("send-message");
Add task to channel:
channel
.add({
label: "Send message",
handler: "SendMessageWorker",
args: "Hello world!",
})
.then(result => {
// do something...
});
Start queue:
channel.start();
That's it!
Click for detailed documentation
$ npm test
Name | Version |
---|---|
Chrome | 32 + |
Firefox | 29 + |
Safari | 8 + |
Opera | 19 + |
IE | 11 |
Edge | all |
Note: Listed above list by pormise support.
You can testing all others browser version at BrowserStack
MIT license
FAQs
Simple client queue mechanism. Create it and run asynchronously with worker class in browser.
The npm package storage-based-queue receives a total of 33 weekly downloads. As such, storage-based-queue popularity was classified as not popular.
We found that storage-based-queue 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.