
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@akylas/load-queue
Advanced tools
Designed to allow running task in a queue with parallel support. Can be used for image or file loading.
Designed to allow running task in a queue with parallel support. Can be used for image (package) or file loading.
Queues types:
npm install load-queue --save
Library is exported via UMD
. From LoadQueue
object you can access to default queue, Queue
and CachedQueue
.
<script src="./dist/load-queue.js" type="text/javascript"></script>
<script>
var queue = new LoadQueue.default(loaderTask)
var queue2 = new LoadQueue.Queue(loaderTask, 1)
var queue3 = new LoadQueue.CachedQueue(loaderTask, 4)
</script>
import Queue from 'load-queue'
var queue = new Queue(loaderTask)
import {Queue} from 'load-queue'
var queue = new Queue(loaderTask)
import {CachedQueue} from 'load-queue'
var queue = new CachedQueue(loaderTask)
Before constructing queue, you must provide your own task implementation. The function will accept 3 arguments:
entry.url
Error
object/**
* @param {QueueEntry} entry
* @param {function} success
* @param {function} failure
*/
var loaderTask = function (entry, success, failure) {
// ... loading entry.url
setTimeout(function () {
if (entry.url === 'url1') {
failure(new Error('Failed!'))
} else {
success('my custom var', 'custom var 2')
// or just success()
}
}, 1000)
}
Queue construct accepts:
var queue = new Queue(loaderTask)
// or
var queue = new Queue(loaderTask, 2)
// or
var queue = new CachedQueue(loaderTask)
To add a new url to load queue, just call add(url, success, error)
. The add method will return the QueueEntry
that holds
given url.
var entry = queue.add('url', function(url, customVar, customVar2) {
console.log(url, customVar, customVar2)
}, function(error) {
console.log(error)
})
console.log(entry.url)
// Or cancel the request
entry.cancel()
You can access to url
and the cancel
method. For internal use you can access to running task entry.task
and call
success/error callbacks (the callbacks that that executes).
You can cancel given url from queue at any time (even when loading - the callbacks wont be called). There are 2 ways how to cancel request.
cancel(url)
on queue
object. Like queue.cancel('test.cz')
cancel()
on QueueEntry
from add
function.If your task implementation needs to handle the cancel (like cancel the http request) then the queue will use it's own logic and then call cancel on the task.
var loaderTask = function (entry, success, failure) {
// ... loading entry.url
var timeout = setTimeout(function () {
if (entry.url === 'url1') {
failure(new Error('Failed!'))
} else {
success('my custom var', 'custom var 2')
// or just success()
}
}, 5000)
// Cancel the timeout
this.cancel = function () {
clearTimeout(timeout)
}
}
load-queue was written by Martin Kluska and is released under the MIT License.
Copyright (c) 2017 Martin Kluska
FAQs
Designed to allow running task in a queue with parallel support. Can be used for image or file loading.
The npm package @akylas/load-queue receives a total of 0 weekly downloads. As such, @akylas/load-queue popularity was classified as not popular.
We found that @akylas/load-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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.