mirror of
https://github.com/Instadapp/Swap-Aggregator-Subgraph.git
synced 2024-07-29 21:57:12 +00:00
24 lines
705 B
JavaScript
24 lines
705 B
JavaScript
'use strict';
|
|
|
|
const promisify = require('es6-promisify');
|
|
|
|
/** * @namespace */
|
|
const PromiseUtils = module.exports;
|
|
|
|
/**
|
|
* Wraps the client request method on an instance, making it return a promise in every case except when the fourth argument is explicitly set to false
|
|
* @param {Function} request The original request method
|
|
* @return {Function}
|
|
*/
|
|
PromiseUtils.wrapClientRequestMethod = function(request) {
|
|
const promisified = promisify(request);
|
|
|
|
return function(method, params, id, shouldCall) {
|
|
if(shouldCall === false) {
|
|
// this should return a raw request for use in batches
|
|
return request(method, params, id);
|
|
}
|
|
return promisified.apply(this, arguments);
|
|
};
|
|
};
|