forked from enviPath/enviPy
Current Dev State
This commit is contained in:
20
static/js/ketcher2/node_modules/orchestrator/LICENSE
generated
vendored
Normal file
20
static/js/ketcher2/node_modules/orchestrator/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2013 [Richardson & Sons, LLC](http://richardsonandsons.com/)
|
||||
|
||||
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.
|
||||
286
static/js/ketcher2/node_modules/orchestrator/README.md
generated
vendored
Normal file
286
static/js/ketcher2/node_modules/orchestrator/README.md
generated
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
[](https://travis-ci.org/robrich/orchestrator)
|
||||
[](https://david-dm.org/robrich/orchestrator)
|
||||
|
||||
Orchestrator
|
||||
============
|
||||
|
||||
A module for sequencing and executing tasks and dependencies in maximum concurrency
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
### 1. Get a reference:
|
||||
|
||||
```javascript
|
||||
var Orchestrator = require('orchestrator');
|
||||
var orchestrator = new Orchestrator();
|
||||
```
|
||||
|
||||
### 2. Load it up with stuff to do:
|
||||
|
||||
```javascript
|
||||
orchestrator.add('thing1', function(){
|
||||
// do stuff
|
||||
});
|
||||
orchestrator.add('thing2', function(){
|
||||
// do stuff
|
||||
});
|
||||
```
|
||||
|
||||
### 3. Run the tasks:
|
||||
|
||||
```javascript
|
||||
orchestrator.start('thing1', 'thing2', function (err) {
|
||||
// all done
|
||||
});
|
||||
```
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
### orchestrator.add(name[, deps][, function]);
|
||||
|
||||
Define a task
|
||||
|
||||
```javascript
|
||||
orchestrator.add('thing1', function(){
|
||||
// do stuff
|
||||
});
|
||||
```
|
||||
|
||||
#### name
|
||||
Type: `String`
|
||||
|
||||
The name of the task.
|
||||
|
||||
#### deps
|
||||
Type: `Array`
|
||||
|
||||
An array of task names to be executed and completed before your task will run.
|
||||
|
||||
```javascript
|
||||
orchestrator.add('mytask', ['array', 'of', 'task', 'names'], function() {
|
||||
// Do stuff
|
||||
});
|
||||
```
|
||||
|
||||
**Note:** Are your tasks running before the dependencies are complete? Make sure your dependency tasks
|
||||
are correctly using the async run hints: take in a callback or return a promise or event stream.
|
||||
|
||||
#### fn
|
||||
Type: `function`
|
||||
|
||||
The function that performs the task's operations. For asynchronous tasks, you need to provide a hint when the task is complete:
|
||||
|
||||
- Take in a callback
|
||||
- Return a stream or a promise
|
||||
|
||||
#### examples:
|
||||
|
||||
**Accept a callback:**
|
||||
|
||||
```javascript
|
||||
orchestrator.add('thing2', function(callback){
|
||||
// do stuff
|
||||
callback(err);
|
||||
});
|
||||
```
|
||||
|
||||
**Return a promise:**
|
||||
|
||||
```javascript
|
||||
var Q = require('q');
|
||||
|
||||
orchestrator.add('thing3', function(){
|
||||
var deferred = Q.defer();
|
||||
|
||||
// do async stuff
|
||||
setTimeout(function () {
|
||||
deferred.resolve();
|
||||
}, 1);
|
||||
|
||||
return deferred.promise;
|
||||
});
|
||||
```
|
||||
|
||||
**Return a stream:** (task is marked complete when stream ends)
|
||||
|
||||
```javascript
|
||||
var map = require('map-stream');
|
||||
|
||||
orchestrator.add('thing4', function(){
|
||||
var stream = map(function (args, cb) {
|
||||
cb(null, args);
|
||||
});
|
||||
// do stream stuff
|
||||
return stream;
|
||||
});
|
||||
```
|
||||
|
||||
**Note:** By default, tasks run with maximum concurrency -- e.g. it launches all the tasks at once and waits for nothing.
|
||||
If you want to create a series where tasks run in a particular order, you need to do two things:
|
||||
|
||||
- give it a hint to tell it when the task is done,
|
||||
- and give it a hint that a task depends on completion of another.
|
||||
|
||||
For these examples, let's presume you have two tasks, "one" and "two" that you specifically want to run in this order:
|
||||
|
||||
1. In task "one" you add a hint to tell it when the task is done. Either take in a callback and call it when you're
|
||||
done or return a promise or stream that the engine should wait to resolve or end respectively.
|
||||
|
||||
2. In task "two" you add a hint telling the engine that it depends on completion of the first task.
|
||||
|
||||
So this example would look like this:
|
||||
|
||||
```javascript
|
||||
var Orchestrator = require('orchestrator');
|
||||
var orchestrator = new Orchestrator();
|
||||
|
||||
// takes in a callback so the engine knows when it'll be done
|
||||
orchestrator.add('one', function (cb) {
|
||||
// do stuff -- async or otherwise
|
||||
cb(err); // if err is not null or undefined, the orchestration will stop, and note that it failed
|
||||
});
|
||||
|
||||
// identifies a dependent task must be complete before this one begins
|
||||
orchestrator.add('two', ['one'], function () {
|
||||
// task 'one' is done now
|
||||
});
|
||||
|
||||
orchestrator.start('one', 'two');
|
||||
```
|
||||
|
||||
### orchestrator.hasTask(name);
|
||||
|
||||
Have you defined a task with this name?
|
||||
|
||||
#### name
|
||||
Type: `String`
|
||||
|
||||
The task name to query
|
||||
|
||||
### orchestrator.start(tasks...[, cb]);
|
||||
|
||||
Start running the tasks
|
||||
|
||||
#### tasks
|
||||
Type: `String` or `Array` of `String`s
|
||||
|
||||
Tasks to be executed. You may pass any number of tasks as individual arguments.
|
||||
|
||||
#### cb
|
||||
Type: `function`: `function (err) {`
|
||||
|
||||
Callback to call after run completed.
|
||||
|
||||
Passes single argument: `err`: did the orchestration succeed?
|
||||
|
||||
**Note:** Tasks run concurrently and therefore may not complete in order.
|
||||
**Note:** Orchestrator uses `sequencify` to resolve dependencies before running, and therefore may not start in order.
|
||||
Listen to orchestration events to watch task running.
|
||||
|
||||
```javascript
|
||||
orchestrator.start('thing1', 'thing2', 'thing3', 'thing4', function (err) {
|
||||
// all done
|
||||
});
|
||||
```
|
||||
```javascript
|
||||
orchestrator.start(['thing1','thing2'], ['thing3','thing4']);
|
||||
```
|
||||
|
||||
**FRAGILE:** Orchestrator catches exceptions on sync runs to pass to your callback
|
||||
but doesn't hook to process.uncaughtException so it can't pass those exceptions
|
||||
to your callback
|
||||
|
||||
**FRAGILE:** Orchestrator will ensure each task and each dependency is run once during an orchestration run
|
||||
even if you specify it to run more than once. (e.g. `orchestrator.start('thing1', 'thing1')`
|
||||
will only run 'thing1' once.) If you need it to run a task multiple times, wait for
|
||||
the orchestration to end (start's callback) then call start again.
|
||||
(e.g. `orchestrator.start('thing1', function () {orchestrator.start('thing1');})`.)
|
||||
Alternatively create a second orchestrator instance.
|
||||
|
||||
### orchestrator.stop()
|
||||
|
||||
Stop an orchestration run currently in process
|
||||
|
||||
**Note:** It will call the `start()` callback with an `err` noting the orchestration was aborted
|
||||
|
||||
### orchestrator.on(event, cb);
|
||||
|
||||
Listen to orchestrator internals
|
||||
|
||||
#### event
|
||||
Type: `String`
|
||||
|
||||
Event name to listen to:
|
||||
- start: from start() method, shows you the task sequence
|
||||
- stop: from stop() method, the queue finished successfully
|
||||
- err: from stop() method, the queue was aborted due to a task error
|
||||
- task_start: from _runTask() method, task was started
|
||||
- task_stop: from _runTask() method, task completed successfully
|
||||
- task_err: from _runTask() method, task errored
|
||||
- task_not_found: from start() method, you're trying to start a task that doesn't exist
|
||||
- task_recursion: from start() method, there are recursive dependencies in your task list
|
||||
|
||||
#### cb
|
||||
Type: `function`: `function (e) {`
|
||||
|
||||
Passes single argument: `e`: event details
|
||||
|
||||
```javascript
|
||||
orchestrator.on('task_start', function (e) {
|
||||
// e.message is the log message
|
||||
// e.task is the task name if the message applies to a task else `undefined`
|
||||
// e.err is the error if event is 'err' else `undefined`
|
||||
});
|
||||
// for task_end and task_err:
|
||||
orchestrator.on('task_stop', function (e) {
|
||||
// e is the same object from task_start
|
||||
// e.message is updated to show how the task ended
|
||||
// e.duration is the task run duration (in seconds)
|
||||
});
|
||||
```
|
||||
|
||||
**Note:** fires either *stop or *err but not both.
|
||||
|
||||
### orchestrator.onAll(cb);
|
||||
|
||||
Listen to all orchestrator events from one callback
|
||||
|
||||
#### cb
|
||||
Type: `function`: `function (e) {`
|
||||
|
||||
Passes single argument: `e`: event details
|
||||
|
||||
```javascript
|
||||
orchestrator.onAll(function (e) {
|
||||
// e is the original event args
|
||||
// e.src is event name
|
||||
});
|
||||
```
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
(MIT License)
|
||||
|
||||
Copyright (c) 2013-2015 [Richardson & Sons, LLC](http://richardsonandsons.com/)
|
||||
|
||||
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.
|
||||
304
static/js/ketcher2/node_modules/orchestrator/index.js
generated
vendored
Normal file
304
static/js/ketcher2/node_modules/orchestrator/index.js
generated
vendored
Normal file
@ -0,0 +1,304 @@
|
||||
/*jshint node:true */
|
||||
|
||||
"use strict";
|
||||
|
||||
var util = require('util');
|
||||
var events = require('events');
|
||||
var EventEmitter = events.EventEmitter;
|
||||
var runTask = require('./lib/runTask');
|
||||
|
||||
var Orchestrator = function () {
|
||||
EventEmitter.call(this);
|
||||
this.doneCallback = undefined; // call this when all tasks in the queue are done
|
||||
this.seq = []; // the order to run the tasks
|
||||
this.tasks = {}; // task objects: name, dep (list of names of dependencies), fn (the task to run)
|
||||
this.isRunning = false; // is the orchestrator running tasks? .start() to start, .stop() to stop
|
||||
};
|
||||
util.inherits(Orchestrator, EventEmitter);
|
||||
|
||||
Orchestrator.prototype.reset = function () {
|
||||
if (this.isRunning) {
|
||||
this.stop(null);
|
||||
}
|
||||
this.tasks = {};
|
||||
this.seq = [];
|
||||
this.isRunning = false;
|
||||
this.doneCallback = undefined;
|
||||
return this;
|
||||
};
|
||||
Orchestrator.prototype.add = function (name, dep, fn) {
|
||||
if (!fn && typeof dep === 'function') {
|
||||
fn = dep;
|
||||
dep = undefined;
|
||||
}
|
||||
dep = dep || [];
|
||||
fn = fn || function () {}; // no-op
|
||||
if (!name) {
|
||||
throw new Error('Task requires a name');
|
||||
}
|
||||
// validate name is a string, dep is an array of strings, and fn is a function
|
||||
if (typeof name !== 'string') {
|
||||
throw new Error('Task requires a name that is a string');
|
||||
}
|
||||
if (typeof fn !== 'function') {
|
||||
throw new Error('Task '+name+' requires a function that is a function');
|
||||
}
|
||||
if (!Array.isArray(dep)) {
|
||||
throw new Error('Task '+name+' can\'t support dependencies that is not an array of strings');
|
||||
}
|
||||
dep.forEach(function (item) {
|
||||
if (typeof item !== 'string') {
|
||||
throw new Error('Task '+name+' dependency '+item+' is not a string');
|
||||
}
|
||||
});
|
||||
this.tasks[name] = {
|
||||
fn: fn,
|
||||
dep: dep,
|
||||
name: name
|
||||
};
|
||||
return this;
|
||||
};
|
||||
Orchestrator.prototype.task = function (name, dep, fn) {
|
||||
if (dep || fn) {
|
||||
// alias for add, return nothing rather than this
|
||||
this.add(name, dep, fn);
|
||||
} else {
|
||||
return this.tasks[name];
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype.hasTask = function (name) {
|
||||
return !!this.tasks[name];
|
||||
};
|
||||
// tasks and optionally a callback
|
||||
Orchestrator.prototype.start = function() {
|
||||
var args, arg, names = [], lastTask, i, seq = [];
|
||||
args = Array.prototype.slice.call(arguments, 0);
|
||||
if (args.length) {
|
||||
lastTask = args[args.length-1];
|
||||
if (typeof lastTask === 'function') {
|
||||
this.doneCallback = lastTask;
|
||||
args.pop();
|
||||
}
|
||||
for (i = 0; i < args.length; i++) {
|
||||
arg = args[i];
|
||||
if (typeof arg === 'string') {
|
||||
names.push(arg);
|
||||
} else if (Array.isArray(arg)) {
|
||||
names = names.concat(arg); // FRAGILE: ASSUME: it's an array of strings
|
||||
} else {
|
||||
throw new Error('pass strings or arrays of strings');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.isRunning) {
|
||||
// reset specified tasks (and dependencies) as not run
|
||||
this._resetSpecificTasks(names);
|
||||
} else {
|
||||
// reset all tasks as not run
|
||||
this._resetAllTasks();
|
||||
}
|
||||
if (this.isRunning) {
|
||||
// if you call start() again while a previous run is still in play
|
||||
// prepend the new tasks to the existing task queue
|
||||
names = names.concat(this.seq);
|
||||
}
|
||||
if (names.length < 1) {
|
||||
// run all tasks
|
||||
for (i in this.tasks) {
|
||||
if (this.tasks.hasOwnProperty(i)) {
|
||||
names.push(this.tasks[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
seq = [];
|
||||
try {
|
||||
this.sequence(this.tasks, names, seq, []);
|
||||
} catch (err) {
|
||||
// Is this a known error?
|
||||
if (err) {
|
||||
if (err.missingTask) {
|
||||
this.emit('task_not_found', {message: err.message, task:err.missingTask, err: err});
|
||||
}
|
||||
if (err.recursiveTasks) {
|
||||
this.emit('task_recursion', {message: err.message, recursiveTasks:err.recursiveTasks, err: err});
|
||||
}
|
||||
}
|
||||
this.stop(err);
|
||||
return this;
|
||||
}
|
||||
this.seq = seq;
|
||||
this.emit('start', {message:'seq: '+this.seq.join(',')});
|
||||
if (!this.isRunning) {
|
||||
this.isRunning = true;
|
||||
}
|
||||
this._runStep();
|
||||
return this;
|
||||
};
|
||||
Orchestrator.prototype.stop = function (err, successfulFinish) {
|
||||
this.isRunning = false;
|
||||
if (err) {
|
||||
this.emit('err', {message:'orchestration failed', err:err});
|
||||
} else if (successfulFinish) {
|
||||
this.emit('stop', {message:'orchestration succeeded'});
|
||||
} else {
|
||||
// ASSUME
|
||||
err = 'orchestration aborted';
|
||||
this.emit('err', {message:'orchestration aborted', err: err});
|
||||
}
|
||||
if (this.doneCallback) {
|
||||
// Avoid calling it multiple times
|
||||
this.doneCallback(err);
|
||||
} else if (err && !this.listeners('err').length) {
|
||||
// No one is listening for the error so speak louder
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype.sequence = require('sequencify');
|
||||
Orchestrator.prototype.allDone = function () {
|
||||
var i, task, allDone = true; // nothing disputed it yet
|
||||
for (i = 0; i < this.seq.length; i++) {
|
||||
task = this.tasks[this.seq[i]];
|
||||
if (!task.done) {
|
||||
allDone = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allDone;
|
||||
};
|
||||
Orchestrator.prototype._resetTask = function(task) {
|
||||
if (task) {
|
||||
if (task.done) {
|
||||
task.done = false;
|
||||
}
|
||||
delete task.start;
|
||||
delete task.stop;
|
||||
delete task.duration;
|
||||
delete task.hrDuration;
|
||||
delete task.args;
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype._resetAllTasks = function() {
|
||||
var task;
|
||||
for (task in this.tasks) {
|
||||
if (this.tasks.hasOwnProperty(task)) {
|
||||
this._resetTask(this.tasks[task]);
|
||||
}
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype._resetSpecificTasks = function (names) {
|
||||
var i, name, t;
|
||||
|
||||
if (names && names.length) {
|
||||
for (i = 0; i < names.length; i++) {
|
||||
name = names[i];
|
||||
t = this.tasks[name];
|
||||
if (t) {
|
||||
this._resetTask(t);
|
||||
if (t.dep && t.dep.length) {
|
||||
this._resetSpecificTasks(t.dep); // recurse
|
||||
}
|
||||
//} else {
|
||||
// FRAGILE: ignore that the task doesn't exist
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype._runStep = function () {
|
||||
var i, task;
|
||||
if (!this.isRunning) {
|
||||
return; // user aborted, ASSUME: stop called previously
|
||||
}
|
||||
for (i = 0; i < this.seq.length; i++) {
|
||||
task = this.tasks[this.seq[i]];
|
||||
if (!task.done && !task.running && this._readyToRunTask(task)) {
|
||||
this._runTask(task);
|
||||
}
|
||||
if (!this.isRunning) {
|
||||
return; // task failed or user aborted, ASSUME: stop called previously
|
||||
}
|
||||
}
|
||||
if (this.allDone()) {
|
||||
this.stop(null, true);
|
||||
}
|
||||
};
|
||||
Orchestrator.prototype._readyToRunTask = function (task) {
|
||||
var ready = true, // no one disproved it yet
|
||||
i, name, t;
|
||||
if (task.dep.length) {
|
||||
for (i = 0; i < task.dep.length; i++) {
|
||||
name = task.dep[i];
|
||||
t = this.tasks[name];
|
||||
if (!t) {
|
||||
// FRAGILE: this should never happen
|
||||
this.stop("can't run "+task.name+" because it depends on "+name+" which doesn't exist");
|
||||
ready = false;
|
||||
break;
|
||||
}
|
||||
if (!t.done) {
|
||||
ready = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ready;
|
||||
};
|
||||
Orchestrator.prototype._stopTask = function (task, meta) {
|
||||
task.duration = meta.duration;
|
||||
task.hrDuration = meta.hrDuration;
|
||||
task.running = false;
|
||||
task.done = true;
|
||||
};
|
||||
Orchestrator.prototype._emitTaskDone = function (task, message, err) {
|
||||
if (!task.args) {
|
||||
task.args = {task:task.name};
|
||||
}
|
||||
task.args.duration = task.duration;
|
||||
task.args.hrDuration = task.hrDuration;
|
||||
task.args.message = task.name+' '+message;
|
||||
var evt = 'stop';
|
||||
if (err) {
|
||||
task.args.err = err;
|
||||
evt = 'err';
|
||||
}
|
||||
// 'task_stop' or 'task_err'
|
||||
this.emit('task_'+evt, task.args);
|
||||
};
|
||||
Orchestrator.prototype._runTask = function (task) {
|
||||
var that = this;
|
||||
|
||||
task.args = {task:task.name, message:task.name+' started'};
|
||||
this.emit('task_start', task.args);
|
||||
task.running = true;
|
||||
|
||||
runTask(task.fn.bind(this), function (err, meta) {
|
||||
that._stopTask.call(that, task, meta);
|
||||
that._emitTaskDone.call(that, task, meta.runMethod, err);
|
||||
if (err) {
|
||||
return that.stop.call(that, err);
|
||||
}
|
||||
that._runStep.call(that);
|
||||
});
|
||||
};
|
||||
|
||||
// FRAGILE: ASSUME: this list is an exhaustive list of events emitted
|
||||
var events = ['start','stop','err','task_start','task_stop','task_err','task_not_found','task_recursion'];
|
||||
|
||||
var listenToEvent = function (target, event, callback) {
|
||||
target.on(event, function (e) {
|
||||
e.src = event;
|
||||
callback(e);
|
||||
});
|
||||
};
|
||||
|
||||
Orchestrator.prototype.onAll = function (callback) {
|
||||
var i;
|
||||
if (typeof callback !== 'function') {
|
||||
throw new Error('No callback specified');
|
||||
}
|
||||
|
||||
for (i = 0; i < events.length; i++) {
|
||||
listenToEvent(this, events[i], callback);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Orchestrator;
|
||||
66
static/js/ketcher2/node_modules/orchestrator/lib/runTask.js
generated
vendored
Normal file
66
static/js/ketcher2/node_modules/orchestrator/lib/runTask.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/*jshint node:true */
|
||||
|
||||
"use strict";
|
||||
|
||||
var eos = require('end-of-stream');
|
||||
var consume = require('stream-consume');
|
||||
|
||||
module.exports = function (task, done) {
|
||||
var that = this, finish, cb, isDone = false, start, r;
|
||||
|
||||
finish = function (err, runMethod) {
|
||||
var hrDuration = process.hrtime(start);
|
||||
|
||||
if (isDone && !err) {
|
||||
err = new Error('task completion callback called too many times');
|
||||
}
|
||||
isDone = true;
|
||||
|
||||
var duration = hrDuration[0] + (hrDuration[1] / 1e9); // seconds
|
||||
|
||||
done.call(that, err, {
|
||||
duration: duration, // seconds
|
||||
hrDuration: hrDuration, // [seconds,nanoseconds]
|
||||
runMethod: runMethod
|
||||
});
|
||||
};
|
||||
|
||||
cb = function (err) {
|
||||
finish(err, 'callback');
|
||||
};
|
||||
|
||||
try {
|
||||
start = process.hrtime();
|
||||
r = task(cb);
|
||||
} catch (err) {
|
||||
return finish(err, 'catch');
|
||||
}
|
||||
|
||||
if (r && typeof r.then === 'function') {
|
||||
// wait for promise to resolve
|
||||
// FRAGILE: ASSUME: Promises/A+, see http://promises-aplus.github.io/promises-spec/
|
||||
r.then(function () {
|
||||
finish(null, 'promise');
|
||||
}, function(err) {
|
||||
finish(err, 'promise');
|
||||
});
|
||||
|
||||
} else if (r && typeof r.pipe === 'function') {
|
||||
// wait for stream to end
|
||||
|
||||
eos(r, { error: true, readable: r.readable, writable: r.writable && !r.readable }, function(err){
|
||||
finish(err, 'stream');
|
||||
});
|
||||
|
||||
// Ensure that the stream completes
|
||||
consume(r);
|
||||
|
||||
} else if (task.length === 0) {
|
||||
// synchronous, function took in args.length parameters, and the callback was extra
|
||||
finish(null, 'sync');
|
||||
|
||||
//} else {
|
||||
// FRAGILE: ASSUME: callback
|
||||
|
||||
}
|
||||
};
|
||||
69
static/js/ketcher2/node_modules/orchestrator/package.json
generated
vendored
Normal file
69
static/js/ketcher2/node_modules/orchestrator/package.json
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"_from": "orchestrator@^0.3.0",
|
||||
"_id": "orchestrator@0.3.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-FOfp4nZPcxX7rBhOUGx6pt+UrX4=",
|
||||
"_location": "/orchestrator",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "orchestrator@^0.3.0",
|
||||
"name": "orchestrator",
|
||||
"escapedName": "orchestrator",
|
||||
"rawSpec": "^0.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gulp"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/orchestrator/-/orchestrator-0.3.8.tgz",
|
||||
"_shasum": "14e7e9e2764f7315fbac184e506c7aa6df94ad7e",
|
||||
"_spec": "orchestrator@^0.3.0",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/gulp",
|
||||
"author": {
|
||||
"name": "Rob Richardson",
|
||||
"url": "http://robrich.org/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/robrich/orchestrator/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"end-of-stream": "~0.1.5",
|
||||
"sequencify": "~0.0.7",
|
||||
"stream-consume": "~0.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A module for sequencing and executing tasks and dependencies in maximum concurrency",
|
||||
"devDependencies": {
|
||||
"event-stream": "~3.3.4",
|
||||
"gulp-uglify": "^2.0.0",
|
||||
"jshint": "^2.9.4",
|
||||
"map-stream": "~0.0.6",
|
||||
"merge-stream": "~1.0.0",
|
||||
"mocha": "~3.1.2",
|
||||
"q": "~1.4.1",
|
||||
"should": "~11.1.1",
|
||||
"vinyl-fs": "~2.4.4"
|
||||
},
|
||||
"homepage": "https://github.com/robrich/orchestrator",
|
||||
"keywords": [
|
||||
"async",
|
||||
"task",
|
||||
"parallel",
|
||||
"compose"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"name": "orchestrator",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/robrich/orchestrator.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"version": "0.3.8"
|
||||
}
|
||||
Reference in New Issue
Block a user