install gulp
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"requireMultipleVarDecl": true,
|
||||
"requireCurlyBraces": ["if", "else", "for", "while", "do"],
|
||||
"disallowLeftStickedOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
|
||||
"disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
|
||||
"requireRightStickedOperators": ["!"],
|
||||
"requireLeftStickedOperators": [","],
|
||||
"disallowKeywords": ["with"],
|
||||
"disallowMulipleLineBreaks": true,
|
||||
"requireAlignedObjectValues": "skipWithLineBreak",
|
||||
"validateJSDoc": {
|
||||
"checkParamNames": true,
|
||||
"requireParamTypes": true
|
||||
},
|
||||
"excludeFiles": [
|
||||
"node_modules",
|
||||
"lib-cov",
|
||||
"html-report"
|
||||
]
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
lib-cov
|
||||
html-report
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"expr" : true,
|
||||
"undef" : true,
|
||||
"predef" : ["describe", "it", "beforeEach", "afterEach"],
|
||||
"node" : true,
|
||||
"boss" : true,
|
||||
"sub" : true,
|
||||
"supernew" : true,
|
||||
"loopfunc" : true,
|
||||
"onecase" : true,
|
||||
"quotmark" : "single"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
.git*
|
||||
test/
|
||||
.DS_Store
|
||||
lib-cov
|
||||
node_modules
|
||||
coverage.html
|
||||
html-report
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
See [releases](https://github.com/dfilatov/vow-queue/releases).
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
Contribution Guide
|
||||
==================
|
||||
|
||||
This document describes some points about contribution process for vow-queue package.
|
||||
|
||||
The maintainer of the project is Dmitry Filatov (dfilatov@yandex-team.ru).
|
||||
|
||||
The project is being developed within community. Maintainer merges pull-requests, fixes critical bugs.
|
||||
|
||||
Pull-requests
|
||||
-------------
|
||||
|
||||
If you fixed or added something useful to the project, you can send pull-request.
|
||||
It will be reviewed by maintainer and accepted, or commented for rework, or declined.
|
||||
|
||||
Bugs
|
||||
----
|
||||
|
||||
If you found an error, mistype or any other flawback in the project, please report about it using github-issues.
|
||||
The more details you provide, the easier it can be reproduced and the faster can be fixed.
|
||||
Unfortunately, sometimes the bug can be only reproduced in your project or in your environment,
|
||||
so maintainers cannot reproduce it. In this case we believe you can fix the bug and send us the fix.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
It you've got an idea about a new feature, it's most likely that you have do implement it on your own.
|
||||
If you cannot implement the feature, but it is very important, you can add a task in github-issues,
|
||||
but expect it be declined by the maintainer.
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013 Dmitry Filatov and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
BIN = ./node_modules/.bin
|
||||
MOCHA = $(BIN)/mocha
|
||||
ISTANBUL = $(BIN)/istanbul
|
||||
JSHINT = $(BIN)/jshint
|
||||
JSCS = $(BIN)/jscs
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(MOCHA) -u bdd -R spec --recursive
|
||||
|
||||
.PHONY: validate
|
||||
validate: lint test
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm -rf lib-cov
|
||||
-rm -rf html-report
|
||||
|
||||
.PHONY: lib-cov
|
||||
lib-cov: clean
|
||||
$(ISTANBUL) instrument --output lib-cov --no-compact --variable global.__coverage__ lib
|
||||
|
||||
.PHONY: coverage
|
||||
coverage: lib-cov
|
||||
VOW_QUEUE_COVERAGE=1 $(MOCHA) -u bdd --reporter mocha-istanbul
|
||||
@echo
|
||||
@echo Open html-report/index.html file in your browser
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
$(JSHINT) .
|
||||
$(JSCS) .
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
vow-queue [](http://badge.fury.io/js/vow-queue) [](http://travis-ci.org/dfilatov/vow-queue)
|
||||
===============
|
||||
|
||||
vow-queue is a module for task queue with weights and priorities
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Module can be installed using `npm`:
|
||||
|
||||
```
|
||||
npm install vow-queue
|
||||
```
|
||||
|
||||
or `bower`:
|
||||
|
||||
```
|
||||
bower install vow-queue
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
````javascript
|
||||
var Queue = require('vow-queue'),
|
||||
queue = new Queue({ weightLimit : 10 });
|
||||
|
||||
queue.enqueue(function() { // simple function
|
||||
return 2 * 2;
|
||||
});
|
||||
|
||||
queue.enqueue(function() { // function returns a promise
|
||||
// do job
|
||||
return promise;
|
||||
});
|
||||
|
||||
queue.enqueue( // task with custom priority and weight
|
||||
function() {
|
||||
// do job
|
||||
},
|
||||
{
|
||||
priority : 3, // this task will be started before the previous two
|
||||
weight : 5
|
||||
});
|
||||
|
||||
queue.start(); // starts tasks processing
|
||||
|
||||
queue.enqueue(function() { }); // and enqueue yet another task
|
||||
````
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name" : "vow-queue",
|
||||
"version" : "0.3.1",
|
||||
"main" : "lib/queue.js",
|
||||
"ignore" : ["**/.*", "node_modules", "test", "utils", "Makefile", ".jshintrc", "package.json", "jscs.json"]
|
||||
}
|
||||
+249
@@ -0,0 +1,249 @@
|
||||
/**
|
||||
* @module vow-queue
|
||||
* @author Filatov Dmitry <dfilatov@yandex-team.ru>
|
||||
* @version 0.3.1
|
||||
* @license
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* * http://www.opensource.org/licenses/mit-license.php
|
||||
* * http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
function getModule(vow, nextTick) {
|
||||
|
||||
var extend = function() {
|
||||
var res = {};
|
||||
|
||||
for(var i = 0, len = arguments.length; i < len; i++) {
|
||||
var obj = arguments[i];
|
||||
if(obj) {
|
||||
for(var key in obj) {
|
||||
obj.hasOwnProperty(key) && (res[key] = obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
},
|
||||
|
||||
DEFAULT_QUEUE_PARAMS = {
|
||||
weightLimit : 100
|
||||
},
|
||||
DEFAULT_TASK_PARAMS = {
|
||||
weight : 1,
|
||||
priority : 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Queue
|
||||
* @exports vow-queue
|
||||
*/
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} [params]
|
||||
* @param {Number} [params.weightLimit=100]
|
||||
*/
|
||||
function Queue(params) {
|
||||
this._pendingTasks = [];
|
||||
this._params = extend(DEFAULT_QUEUE_PARAMS, params);
|
||||
this._curWeight = 0;
|
||||
this._isRunScheduled = false;
|
||||
this._isStopped = true;
|
||||
this._processedBuffer = [];
|
||||
this._stats = {
|
||||
pendingTasksCount : 0,
|
||||
processingTasksCount : 0,
|
||||
processedTasksCount : 0
|
||||
};
|
||||
}
|
||||
|
||||
Queue.prototype = /** @lends Queue.prototype */ {
|
||||
/**
|
||||
* Adds task to queue
|
||||
*
|
||||
* @param {Function} taskFn
|
||||
* @param {Object} [taskParams]
|
||||
* @param {Number} [taskParams.weight=1]
|
||||
* @param {Number} [taskParams.priority=1]
|
||||
* @returns {vow:promise}
|
||||
*/
|
||||
enqueue : function(taskFn, taskParams) {
|
||||
var task = this._buildTask(taskFn, taskParams);
|
||||
|
||||
if(task.params.weight > this._params.weightLimit) {
|
||||
throw Error('task with weight of ' +
|
||||
task.params.weight +
|
||||
' can\'t be performed in queue with limit of ' +
|
||||
this._params.weightLimit);
|
||||
}
|
||||
|
||||
this._enqueueTask(task);
|
||||
this._isStopped || this._scheduleRun();
|
||||
|
||||
task.defer.promise().always(
|
||||
function() {
|
||||
this._stats.processingTasksCount--;
|
||||
this._stats.processedTasksCount++;
|
||||
},
|
||||
this);
|
||||
|
||||
return task.defer.promise();
|
||||
},
|
||||
|
||||
/**
|
||||
* Starts processing of queue
|
||||
*/
|
||||
start : function() {
|
||||
if(!this._isStopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isStopped = false;
|
||||
var processedBuffer = this._processedBuffer;
|
||||
if(processedBuffer.length) {
|
||||
this._processedBuffer = [];
|
||||
nextTick(function() {
|
||||
while(processedBuffer.length) {
|
||||
processedBuffer.shift()();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this._hasPendingTasks() && this._scheduleRun();
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops processing of queue
|
||||
*/
|
||||
stop : function() {
|
||||
this._isStopped = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the queue is started
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isStarted : function() {
|
||||
return !this._isStopped;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets params of queue
|
||||
*
|
||||
* @param {Object} params
|
||||
* @param {Number} [params.weightLimit]
|
||||
*/
|
||||
params : function(params) {
|
||||
if(typeof params.weightLimit !== 'undefined') {
|
||||
this._params.weightLimit = params.weightLimit;
|
||||
this._scheduleRun();
|
||||
}
|
||||
},
|
||||
|
||||
getStats : function() {
|
||||
return this._stats;
|
||||
},
|
||||
|
||||
_buildTask : function(taskFn, taskParams) {
|
||||
return {
|
||||
fn : taskFn,
|
||||
params : extend(DEFAULT_TASK_PARAMS, taskParams),
|
||||
defer : vow.defer()
|
||||
};
|
||||
},
|
||||
|
||||
_enqueueTask : function(task) {
|
||||
var pendingTasks = this._pendingTasks,
|
||||
i = pendingTasks.length;
|
||||
|
||||
this._stats.pendingTasksCount++;
|
||||
|
||||
while(i) {
|
||||
if(pendingTasks[i - 1].params.priority >= task.params.priority) {
|
||||
i === pendingTasks.length?
|
||||
pendingTasks.push(task) :
|
||||
pendingTasks.splice(i, 0, task);
|
||||
return;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
|
||||
pendingTasks.push(task);
|
||||
},
|
||||
|
||||
_scheduleRun : function() {
|
||||
if(!this._isRunScheduled) {
|
||||
this._isRunScheduled = true;
|
||||
nextTick(this._run.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
_run : function() {
|
||||
this._isRunScheduled = false;
|
||||
while(this._hasPendingTasks() && this._allowRunTask(this._pendingTasks[0])) {
|
||||
this._runTask(this._pendingTasks.shift());
|
||||
}
|
||||
},
|
||||
|
||||
_hasPendingTasks : function() {
|
||||
return !!this._pendingTasks.length;
|
||||
},
|
||||
|
||||
_allowRunTask : function(task) {
|
||||
return this._curWeight + task.params.weight <= this._params.weightLimit;
|
||||
},
|
||||
|
||||
_runTask : function(task) {
|
||||
this._curWeight += task.params.weight;
|
||||
|
||||
this._stats.pendingTasksCount--;
|
||||
this._stats.processingTasksCount++;
|
||||
|
||||
var taskRes = vow.invoke(task.fn);
|
||||
|
||||
taskRes
|
||||
.progress(
|
||||
task.defer.notify,
|
||||
task.defer)
|
||||
.always(
|
||||
function() {
|
||||
this._curWeight -= task.params.weight;
|
||||
if(this._isStopped) {
|
||||
this._processedBuffer.push(function() {
|
||||
task.defer.resolve(taskRes);
|
||||
});
|
||||
}
|
||||
else {
|
||||
task.defer.resolve(taskRes);
|
||||
this._scheduleRun();
|
||||
}
|
||||
},
|
||||
this);
|
||||
}
|
||||
};
|
||||
|
||||
return Queue;
|
||||
|
||||
}
|
||||
|
||||
var nextTick = typeof setImmediate !== 'undefined'?
|
||||
setImmediate :
|
||||
typeof process === 'object' && process.nextTick?
|
||||
process.nextTick :
|
||||
function(fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
|
||||
if(typeof modules !== 'undefined') {
|
||||
/* global modules */
|
||||
modules.define('vow-queue', ['vow'], function(provide, vow) {
|
||||
provide(getModule(vow, nextTick));
|
||||
});
|
||||
}
|
||||
else if(typeof exports === 'object') {
|
||||
module.exports = getModule(require('vow'), nextTick);
|
||||
}
|
||||
|
||||
})();
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"vow-queue@0.3.1",
|
||||
"/mnt/data/Sites/anissabensalah.net/user/themes/anissabensalah"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "vow-queue@0.3.1",
|
||||
"_id": "vow-queue@0.3.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WYxRoVsKgabV/AX0dhzrRi3h6Gg=",
|
||||
"_location": "/vow-queue",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "vow-queue@0.3.1",
|
||||
"name": "vow-queue",
|
||||
"escapedName": "vow-queue",
|
||||
"rawSpec": "0.3.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.3.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vow-fs"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/vow-queue/-/vow-queue-0.3.1.tgz",
|
||||
"_spec": "0.3.1",
|
||||
"_where": "/mnt/data/Sites/anissabensalah.net/user/themes/anissabensalah",
|
||||
"author": {
|
||||
"name": "Dmitry Filatov",
|
||||
"email": "dfilatov@yandex-team.ru"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/dfilatov/vow-queue/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Dmitry Filatov",
|
||||
"email": "dfilatov@yandex-team.ru"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"vow": "~0.4.0"
|
||||
},
|
||||
"description": "Vow-based task queue",
|
||||
"devDependencies": {
|
||||
"chai": "*",
|
||||
"istanbul": "0.1.39",
|
||||
"jscs": "1.0.0",
|
||||
"jshint": "2.1.3",
|
||||
"mocha": "1.11.0",
|
||||
"mocha-istanbul": "*",
|
||||
"vow": "~0.4.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
},
|
||||
"homepage": "https://github.com/dfilatov/vow-queue#readme",
|
||||
"main": "lib/queue",
|
||||
"name": "vow-queue",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/dfilatov/vow-queue.git"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "make clean",
|
||||
"coverage": "make coverage",
|
||||
"lint": "make lint",
|
||||
"test": "make validate"
|
||||
},
|
||||
"version": "0.3.1"
|
||||
}
|
||||
Reference in New Issue
Block a user