forked from enviPath/enviPy
Current Dev State
This commit is contained in:
19
static/js/ketcher2/node_modules/function-loop/README.md
generated
vendored
Normal file
19
static/js/ketcher2/node_modules/function-loop/README.md
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# function-loop
|
||||
|
||||
Run a list of functions in order in a given object context. The
|
||||
functions can be callback-taking or promise-returning.
|
||||
|
||||
This module is
|
||||
[zalgo-exposing](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony),
|
||||
meaning that synchronous calls to the cb functions will result in a
|
||||
sync call to the supplied cb, and async calls will result in the cb
|
||||
being called asynchronously. It does not artificially defer if
|
||||
callbacks are called synchronously.
|
||||
|
||||
## API
|
||||
|
||||
`loop(context, functionList, doneCallback, errorCallback)`
|
||||
|
||||
Run all the functions in the context of the `context` object, and then
|
||||
call the `doneCallback` or call the `errorCallback` if there are any
|
||||
errors.
|
||||
36
static/js/ketcher2/node_modules/function-loop/index.js
generated
vendored
Normal file
36
static/js/ketcher2/node_modules/function-loop/index.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
module.exports = loop
|
||||
|
||||
// this weird little engine is to loop if the cb's keep getting
|
||||
// called synchronously, since that's faster and makes shallower
|
||||
// stack traces, but recurse if any of them don't fire this tick
|
||||
|
||||
function loop (self, arr, cb, onerr, i) {
|
||||
if (!i)
|
||||
i = 0
|
||||
|
||||
var running = false
|
||||
while (i < arr.length && !running) {
|
||||
running = true
|
||||
var sync = true
|
||||
try {
|
||||
var ret = arr[i].call(self, next)
|
||||
} catch (er) {
|
||||
return onerr.call(self,er)
|
||||
}
|
||||
if (ret && typeof ret.then === 'function')
|
||||
ret.then(next.bind(self, null), onerr.bind(self))
|
||||
i++
|
||||
sync = false
|
||||
}
|
||||
|
||||
function next (er) {
|
||||
if (er)
|
||||
return onerr.call(self, er)
|
||||
else if (!sync)
|
||||
return loop(self, arr, cb, onerr, i)
|
||||
running = false
|
||||
}
|
||||
|
||||
if (i >= arr.length && !running)
|
||||
return cb.call(self)
|
||||
}
|
||||
52
static/js/ketcher2/node_modules/function-loop/package.json
generated
vendored
Normal file
52
static/js/ketcher2/node_modules/function-loop/package.json
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
{
|
||||
"_from": "function-loop@^1.0.1",
|
||||
"_id": "function-loop@1.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-gHa7MF6OajzO7ikgdl8zDRkPNAw=",
|
||||
"_location": "/function-loop",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "function-loop@^1.0.1",
|
||||
"name": "function-loop",
|
||||
"escapedName": "function-loop",
|
||||
"rawSpec": "^1.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/tap"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/function-loop/-/function-loop-1.0.1.tgz",
|
||||
"_shasum": "8076bb305e8e6a3cceee2920765f330d190f340c",
|
||||
"_spec": "function-loop@^1.0.1",
|
||||
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/tap",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/function-loop/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Run a list of functions in order in a given object context. The functions can be callback-taking or promise-returning.",
|
||||
"devDependencies": {
|
||||
"tap": "^9.0.3"
|
||||
},
|
||||
"homepage": "https://github.com/isaacs/function-loop#readme",
|
||||
"keywords": [],
|
||||
"license": "ISC",
|
||||
"main": "index.js",
|
||||
"name": "function-loop",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/isaacs/function-loop.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test.js --100"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
107
static/js/ketcher2/node_modules/function-loop/test.js
generated
vendored
Normal file
107
static/js/ketcher2/node_modules/function-loop/test.js
generated
vendored
Normal file
@ -0,0 +1,107 @@
|
||||
var t = require('tap')
|
||||
var loop = require('./')
|
||||
var obj = {}
|
||||
|
||||
t.test('basic passing operation', function (t) {
|
||||
var i = 0
|
||||
loop(obj, [
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct 1')
|
||||
t.equal(i, 0, '0')
|
||||
cb()
|
||||
i++
|
||||
},
|
||||
function () {
|
||||
t.equal(this, obj, 'this is correct 2')
|
||||
t.equal(i++, 1, '1')
|
||||
return Promise.resolve(true)
|
||||
},
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct 3')
|
||||
t.equal(i++, 2, '2')
|
||||
setTimeout(cb)
|
||||
},
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct 4')
|
||||
t.equal(i++, 3, '3')
|
||||
process.nextTick(cb)
|
||||
}
|
||||
], function () {
|
||||
t.equal(this, obj, 'this is correct 5')
|
||||
t.equal(i++, 4, '4')
|
||||
t.end()
|
||||
}, function (er) {
|
||||
throw er
|
||||
})
|
||||
t.equal(i, 2, '2, after loop() call')
|
||||
})
|
||||
|
||||
t.test('throws', function (t) {
|
||||
loop(obj, [
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct')
|
||||
throw new Error('foo')
|
||||
},
|
||||
function () {
|
||||
t.fail('should not get here')
|
||||
}
|
||||
], function () {
|
||||
t.fail('should not get here')
|
||||
}, function (er) {
|
||||
t.match(er, { message: 'foo' })
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('all sync', function (t) {
|
||||
var i = 0
|
||||
loop(obj, [
|
||||
function (cb) { t.equal(i++, 0); cb() },
|
||||
function (cb) { t.equal(i++, 1); cb() },
|
||||
function (cb) { t.equal(i++, 2); cb() },
|
||||
function (cb) { t.equal(i++, 3); cb() },
|
||||
function (cb) { t.equal(i++, 4); cb() }
|
||||
], function () {
|
||||
t.equal(i++, 5)
|
||||
}, function (er) {
|
||||
throw er
|
||||
})
|
||||
t.equal(i, 6)
|
||||
t.end()
|
||||
})
|
||||
|
||||
t.test('broken promise', function (t) {
|
||||
loop(obj, [
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct')
|
||||
return Promise.reject(new Error('foo'))
|
||||
},
|
||||
function () {
|
||||
t.fail('should not get here')
|
||||
}
|
||||
], function () {
|
||||
t.fail('should not get here')
|
||||
}, function (er) {
|
||||
t.equal(this, obj, 'this is correct')
|
||||
t.match(er, { message: 'foo' })
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
t.test('cb err', function (t) {
|
||||
loop(obj, [
|
||||
function (cb) {
|
||||
t.equal(this, obj, 'this is correct')
|
||||
cb(new Error('foo'))
|
||||
},
|
||||
function () {
|
||||
t.fail('should not get here')
|
||||
}
|
||||
], function () {
|
||||
t.fail('should not get here')
|
||||
}, function (er) {
|
||||
t.equal(this, obj, 'this is correct')
|
||||
t.match(er, { message: 'foo' })
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user