Skip to content

Commit

Permalink
Add changes from Update Documentation Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 23, 2020
1 parent 8eee3f2 commit 9ede2f0
Show file tree
Hide file tree
Showing 37 changed files with 684 additions and 693 deletions.
18 changes: 13 additions & 5 deletions build/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ export interface RetryOptions {
timeout?: number;
}
export interface PromisifyAllObjectParam {
[key: string]: (...args: any[]) => void | PromisifyAllObjectParam;
[key: string]: ((...args: any[]) => void) | any;
}
export interface PromisifyAllObjectResult {
[key: string]: (<T>(...args: any[]) => Promisie<T>) | PromisifyAllObjectResult;
[key: string]: (<T>(...args: any[]) => Promisie<T>) | any;
}
export default class Promisie<T = any> extends Promise<T> {
[key: string]: Function;
constructor(callback: (resolve: (value?: T | PromiseLike<T>) => void, reject: (value?: T | PromiseLike<T>) => void) => void);
then<TSuccess = T, TFailure = any>(onfulfilled?: ((value: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined): Promisie<TSuccess>;
try<TSuccess = T, TFailure = any>(onfulfilled?: ((value: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined): Promisie<TSuccess>;
spread<TSuccess = T, TFailure = any>(onfulfilled?: ((...args: T[]) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined): Promisie<TSuccess>;
map<TSuccess = T, TFailure = any>(onfulfilled?: ((datas: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined | number, concurrency?: number): Promisie<TSuccess[]>;
each<TSuccess = T, TFailure = any>(onfulfilled?: ((datas: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined | number, concurrency?: number): Promisie<TSuccess[]>;
settle<TSuccess = T, TFailure = any>(onfulfilled?: ((datas: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined): Promisie<SettleValues<TSuccess>>;
retry<TSuccess = T, TFailure = any>(onfulfilled?: ((args: T) => any) | null | undefined, onrejected?: ((reason: any) => TFailure | PromiseLike<TFailure>) | null | undefined | RetryOptions, options?: RetryOptions): Promisie<TSuccess>;
finally<TSuccess = T>(onfulfilled?: (() => any) | null | undefined): Promisie<TSuccess>;
static promisify(fn: (...args: any[]) => void, _this?: any): <T = any>(...args: any[]) => Promisie<T>;
static promisifyAll(mod: PromisifyAllObjectParam, _this?: any, options?: PromisifyAllOptions): PromisifyAllObjectResult;
static series<T = any>(fns: Array<(...args: any[]) => any>): Promise<T>;
static pipe<T = any>(fns: Array<(...args: any[]) => any>): (...args: any[]) => Promise<T>;
static compose<T = any>(fns: Array<(...args: any[]) => any>): (...args: any[]) => Promise<T>;
static series<T = any>(fns: Array<((state: any) => any) | any[]>): Promisie<T>;
static pipe<T = any>(fns: Array<(...args: any[]) => any>): (...args: any[]) => Promisie<T>;
static compose<T = any>(fns: Array<(...args: any[]) => any>): (...args: any[]) => Promisie<T>;
static map<T = any>(datas: any[], concurrency: any, fn?: (arg: any) => any): Promisie<Array<T>>;
static each<T = any>(datas: T[], concurrency: any, fn?: (arg: any) => any): Promisie<Array<T>>;
static parallel<T = any>(fns: {
Expand Down
133 changes: 68 additions & 65 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,104 +9,102 @@ function setHandlers(success, failure) {
};
}
;
const thenables = {
try(onSuccess, onFailure) {
export default class Promisie extends Promise {
constructor(callback) {
super(callback);
}
then(onfulfilled, onrejected) {
return super.then(onfulfilled, onrejected);
}
try(onfulfilled, onrejected) {
const { success, failure } = setHandlers(function (data) {
try {
return (typeof onSuccess === 'function')
? onSuccess(data)
return (typeof onfulfilled === 'function')
? onfulfilled(data)
: Promisie.reject(new TypeError('ERROR: try expects onSuccess handler to be a function'));
}
catch (e) {
return Promisie.reject(e);
}
}, onFailure);
}, onrejected);
return this.then(success, failure);
},
spread(onSuccess, onFailure) {
}
spread(onfulfilled, onrejected) {
const { success, failure } = setHandlers(function (data) {
if (typeof data[Symbol.iterator] !== 'function') {
return Promisie.reject(new TypeError('ERROR: spread expects input to be iterable'));
}
if (typeof onSuccess !== 'function') {
if (typeof onfulfilled !== 'function') {
return Promisie.reject(new TypeError('ERROR: spread expects onSuccess handler to be a function'));
}
return onSuccess(...data);
}, onFailure);
return onfulfilled(...data);
}, onrejected);
return this.then(success, failure);
},
map(onSuccess, onFailure, concurrency) {
if (typeof onFailure === 'number') {
concurrency = onFailure;
onFailure = undefined;
}
map(onfulfilled, onrejected, concurrency) {
if (typeof onrejected === 'number') {
concurrency = onrejected;
onrejected = undefined;
}
const { success, failure } = setHandlers(function (data) {
if (!Array.isArray(data)) {
return Promisie.reject(new TypeError('ERROR: map expects input to be an array'));
}
if (typeof onSuccess !== 'function') {
if (typeof onfulfilled !== 'function') {
return Promisie.reject(new TypeError('ERROR: map expects onSuccess handler to be a function'));
}
return Promisie.map(data, concurrency, onSuccess);
}, onFailure);
return Promisie.map(data, concurrency, onfulfilled);
}, onrejected);
return this.then(success, failure);
},
each(onSuccess, onFailure, concurrency) {
if (typeof onFailure === 'number') {
concurrency = onFailure;
onFailure = undefined;
}
each(onfulfilled, onrejected, concurrency) {
if (typeof onrejected === 'number') {
concurrency = onrejected;
onrejected = undefined;
}
const { success, failure } = setHandlers(function (data) {
if (!Array.isArray(data)) {
return Promisie.reject(new TypeError('ERROR: each expects input to be an array'));
}
if (typeof onSuccess !== 'function') {
if (typeof onfulfilled !== 'function') {
return Promisie.reject(new TypeError('ERROR: each expects onSuccess handler to be a function'));
}
return Promisie.each(data, concurrency, onSuccess);
}, onFailure);
return Promisie.each(data, concurrency, onfulfilled);
}, onrejected);
return this.then(success, failure);
},
settle(onSuccess, onFailure) {
let { success, failure } = setHandlers(function (data) {
}
settle(onfulfilled, onrejected) {
const { success, failure } = setHandlers(function (data) {
if (!Array.isArray(data)) {
return Promisie.reject(new TypeError('ERROR: settle expects input to be an array'));
}
if (typeof onSuccess !== 'function') {
if (typeof onfulfilled !== 'function') {
return Promisie.reject(new TypeError('ERROR: settle expects onSuccess handler to be a function'));
}
let operations = data.map(d => () => onSuccess(d));
const operations = data.map(d => () => onfulfilled(d));
return Promisie.settle(operations);
}, onFailure);
}, onrejected);
return this.then(success, failure);
},
retry(onSuccess, onFailure, options) {
if (typeof onFailure === 'object') {
options = onFailure;
onFailure = undefined;
}
retry(onfulfilled, onrejected, options) {
if (onrejected && typeof onrejected === 'object') {
options = onrejected;
onrejected = undefined;
}
let { success, failure } = setHandlers(function (data) {
if (typeof onSuccess !== 'function')
const { success, failure } = setHandlers(function (data) {
if (typeof onfulfilled !== 'function')
return Promisie.reject(new TypeError('ERROR: retry expects onSuccess handler to be a function'));
return Promisie.retry(() => {
return onSuccess(data);
return onfulfilled(data);
}, options);
}, onFailure);
}, onrejected);
return this.then(success, failure);
},
finally(onSuccess) {
let _handler = () => (typeof onSuccess === 'function')
? onSuccess()
}
finally(onfulfilled) {
const _handler = () => (typeof onfulfilled === 'function')
? onfulfilled()
: Promisie.reject(new TypeError('ERROR: finally expects handler to be a function'));
return this.then(_handler, _handler);
},
};
export default class Promisie extends Promise {
constructor(callback) {
super(callback);
for (let key in thenables) {
this[key] = thenables[key].bind(this);
}
}
static promisify(fn, _this) {
const promisified = function (...args) {
Expand Down Expand Up @@ -155,21 +153,17 @@ export default class Promisie extends Promise {
});
return promisified;
}
static async series(fns) {
let last;
for (let i = 0; i < fns.length; i++) {
last = await fns[i](last);
}
return last;
static series(fns) {
return Promisie.iterate(utilities.series(fns), null);
}
static pipe(fns) {
return async function (...args) {
return function (...args) {
const operations = Object.assign([], fns);
const first = operations[0];
operations[0] = function () {
return first(...args);
};
return await Promisie.series(fns);
return Promisie.series(operations);
};
}
static compose(fns) {
Expand All @@ -179,6 +173,9 @@ export default class Promisie extends Promise {
const method = (typeof concurrency === 'function')
? concurrency
: fn;
if (typeof concurrency !== 'number') {
concurrency = 1;
}
return Promisie.promisify(utilities.map)(method, datas, concurrency);
}
static each(datas, concurrency, fn) {
Expand All @@ -197,7 +194,8 @@ export default class Promisie extends Promise {
return Promisie.promisify(utilities.settle)(fns, concurrency);
}
static iterate(generator, initial) {
return Promisie.promisify(utilities.iterator)(generator(initial));
const iterator = utilities.iterator(generator(initial));
return Promisie.promisify(iterator)(initial);
}
static doWhilst(fn, evaluate) {
return Promisie.iterate(utilities.doWhilst(fn, evaluate), null);
Expand All @@ -211,8 +209,13 @@ export default class Promisie extends Promise {
}
static retry(fn, options) {
const { times = 3, timeout = 0 } = options || {};
return Promisie.iterate(utilities.retry(fn, { times, timeout }), null);
return Promisie.iterate(utilities.retry(fn, { times, timeout }), null)
.then(result => {
const { __isRejected, e, value } = result;
if (__isRejected) {
return Promisie.reject(e);
}
return Promisie.resolve(value);
});
}
}
// const p = Promisie;
// export default p;
2 changes: 2 additions & 0 deletions build/utilities/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import settle from './settle';
import iterator from './iterator';
import doWhilst from './dowhilst';
import retry from './retry';
import series from './series';
declare const _default: {
safeAssign: typeof safeAssign;
map: typeof map;
Expand All @@ -14,5 +15,6 @@ declare const _default: {
iterator: typeof iterator;
doWhilst: typeof doWhilst;
retry: typeof retry;
series: typeof series;
};
export default _default;
2 changes: 2 additions & 0 deletions build/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import settle from './settle';
import iterator from './iterator';
import doWhilst from './dowhilst';
import retry from './retry';
import series from './series';
export default {
safeAssign,
map,
Expand All @@ -14,4 +15,5 @@ export default {
iterator,
doWhilst,
retry,
series,
};
2 changes: 1 addition & 1 deletion build/utilities/iterator.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default function iterator(generator: Generator, cb: (...args: any[]) => void): (state: any) => void;
export default function iterator(generator: Generator): (state: any, cb: (...args: any[]) => void) => void;
8 changes: 4 additions & 4 deletions build/utilities/iterator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function iterator(generator, cb) {
return function iterate(state) {
export default function iterator(generator) {
return function iterate(state, cb) {
let current;
try {
current = generator.next(state);
Expand All @@ -13,11 +13,11 @@ export default function iterator(generator, cb) {
const { done, value } = current || { done: true, value: null };
if (!done) {
if (value && typeof value.then === 'function' && typeof value.catch === 'function') {
value.then(iterate, cb);
value.then((next) => iterate(next, cb), cb);
}
else {
let timeout = setTimeout(() => {
iterate(value);
iterate(value, cb);
clearTimeout(timeout);
}, 0);
}
Expand Down
6 changes: 3 additions & 3 deletions build/utilities/parallel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function parallel(fns, args, concurrency, cb) {
const params = args;
return Promise.all([operation(...params), key]);
}
return [operation(args), key];
return Promise.all([operation(args), key]);
}
return [operation, key];
},
Expand All @@ -28,7 +28,7 @@ export default function parallel(fns, args, concurrency, cb) {
},
});
const p = queue
.insert(...Object.keys(fns).map(key => [fns[key], key]))
.insert(...Object.keys(fns).map(key => ({ operation: fns[key], key })))
.resolve();
return p
.then(result => callback(null, result))
Expand All @@ -40,7 +40,7 @@ export function handleRecursiveParallel(fns) {
result[key] = () => (Promisie.parallel(handleRecursiveParallel(fns[key])));
}
else {
result[key] = key;
result[key] = fns[key];
}
return result;
}, {});
Expand Down
2 changes: 1 addition & 1 deletion build/utilities/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function handleResolve(resolve, reject) {
current.resolve(current.value)
.then(result => {
if (--this.active === 0 && !this.current)
resolve(decompress(this.root));
resolve(this.decompress(this.root));
else
this.resolve(resolve, reject);
}, e => {
Expand Down
6 changes: 3 additions & 3 deletions build/utilities/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export default function makeRetryGenerator(fn, options) {
if (invoked && typeof invoked.then === 'function' && typeof invoked.catch === 'function') {
yield invoked
.then((result) => {
current = result;
current = { __isRejected: false, e: null, value: result };
return current;
}, (e) => {
current = { __isRejected: true, e };
current = { __isRejected: true, e, value: null };
return current;
});
}
else {
current = invoked;
current = { __isRejected: false, e: null, value: invoked };
yield current;
}
} while (times
Expand Down
2 changes: 1 addition & 1 deletion build/utilities/settle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function settle(fns, concurrency, cb) {
try {
const invoked = operation();
if (invoked && typeof invoked.then === 'function' && typeof invoked.catch === 'function') {
invoked
return invoked
.then((result) => {
fulfilled.push({ value: result, status: 'fulfilled' });
}, (err) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

Loading

0 comments on commit 9ede2f0

Please sign in to comment.