mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
* first action! (#1)
This commit is contained in:
parent
8deacc95b1
commit
ace1e6a69a
3750 changed files with 1155519 additions and 0 deletions
52
node_modules/promise-retry/index.js
generated
vendored
Normal file
52
node_modules/promise-retry/index.js
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
'use strict';
|
||||
|
||||
var errcode = require('err-code');
|
||||
var retry = require('retry');
|
||||
|
||||
var hasOwn = Object.prototype.hasOwnProperty;
|
||||
|
||||
function isRetryError(err) {
|
||||
return err && err.code === 'EPROMISERETRY' && hasOwn.call(err, 'retried');
|
||||
}
|
||||
|
||||
function promiseRetry(fn, options) {
|
||||
var temp;
|
||||
var operation;
|
||||
|
||||
if (typeof fn === 'object' && typeof options === 'function') {
|
||||
// Swap options and fn when using alternate signature (options, fn)
|
||||
temp = options;
|
||||
options = fn;
|
||||
fn = temp;
|
||||
}
|
||||
|
||||
operation = retry.operation(options);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
operation.attempt(function (number) {
|
||||
Promise.resolve()
|
||||
.then(function () {
|
||||
return fn(function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
}
|
||||
|
||||
throw errcode('Retrying', 'EPROMISERETRY', { retried: err });
|
||||
}, number);
|
||||
})
|
||||
.then(resolve, function (err) {
|
||||
if (isRetryError(err)) {
|
||||
err = err.retried;
|
||||
|
||||
if (operation.retry(err || new Error())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = promiseRetry;
|
Loading…
Add table
Add a link
Reference in a new issue