Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/wincloud_gateway/node_modules/cls-bluebird/lib/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict';
/*
* cls-bluebird
* Function to shim `Promise.coroutine`
*
* Works by binding the `.next()` and `.throw()` methods of generator to CLS context
* at time when coroutine is executed.
*
* In bluebird v3.x, running the coroutine internally calls `.lastly()` if cancellation is enabled.
* To prevent unnecessary binding of the `.lastly()` callback to CLS context, this patch
* temporarily disables the patch on `Promise.prototype.lastly`.
* NB This patch could break if bluebird internals change, but this is covered by the tests.
*/
// Modules
var shimmer = require('shimmer');
// Exports
/**
* Patch `Promise.coroutine` or `Promise.spawn` to maintain current CLS context after all `yield` statements.
*
* @param {string} methodName - method name (either 'coroutine' or 'spawn')
* @param {Function} Promise - Bluebird Promise constructor to patch
* @param {Object} ns - CLS namespace to bind callbacks to
* @returns {undefined}
*/
module.exports = function(methodName, Promise, ns, v3) {
var lastlyPatched = Promise.prototype.lastly,
lastlyOriginal = Promise.prototype.lastly.__original;
// Patch method
shimmer.wrap(Promise, methodName, function(original) {
return function(generatorFunction, options) {
// NB If `generatorFunction` is not a function, do not alter it.
// Pass value directly to bluebird which will throw an error.
if (typeof generatorFunction === 'function') {
// Create proxy generator function
var generatorFunctionOriginal = generatorFunction;
generatorFunction = function() {
// Create generator from generator function
var generator = generatorFunctionOriginal.apply(this, arguments);
// Bind `.next()`, '.throw()' and `.return()` to current CLS context.
// NB CLS context is from when coroutine is called, not when created.
['next', 'throw', 'return'].forEach(function(name) {
if (typeof generator[name] === 'function') generator[name] = ns.bind(generator[name]);
});
return generator;
};
}
// Temporarily remove patch from `Promise.prototype.lastly` in bluebird v3
// to avoid unnecessary binding to CLS context.
var self = this;
if (methodName === 'spawn' && v3) {
return tempPatchLastly(function() {
return original.call(self, generatorFunction, options);
});
}
var fn = original.call(this, generatorFunction, options);
if (methodName === 'coroutine' && v3) {
return function() {
var self = this, args = arguments;
return tempPatchLastly(function() {
return fn.apply(self, args);
});
};
}
return fn;
};
});
function tempPatchLastly(fn) {
Promise.prototype.lastly = lastlyOriginal;
var res = fn();
Promise.prototype.lastly = lastlyPatched;
return res;
}
};
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0146 ]-- |