mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
54
node_modules/mongoose/lib/helpers/promiseOrCallback.js
generated
vendored
Normal file
54
node_modules/mongoose/lib/helpers/promiseOrCallback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
const immediate = require('./immediate');
|
||||
|
||||
const emittedSymbol = Symbol('mongoose:emitted');
|
||||
|
||||
module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
|
||||
if (typeof callback === 'function') {
|
||||
try {
|
||||
return fn(function(error) {
|
||||
if (error != null) {
|
||||
if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
|
||||
error[emittedSymbol] = true;
|
||||
ee.emit('error', error);
|
||||
}
|
||||
try {
|
||||
callback(error);
|
||||
} catch (error) {
|
||||
return immediate(() => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
callback.apply(this, arguments);
|
||||
});
|
||||
} catch (error) {
|
||||
if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
|
||||
error[emittedSymbol] = true;
|
||||
ee.emit('error', error);
|
||||
}
|
||||
|
||||
return callback(error);
|
||||
}
|
||||
}
|
||||
|
||||
Promise = Promise || global.Promise;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
fn(function(error, res) {
|
||||
if (error != null) {
|
||||
if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
|
||||
error[emittedSymbol] = true;
|
||||
ee.emit('error', error);
|
||||
}
|
||||
return reject(error);
|
||||
}
|
||||
if (arguments.length > 2) {
|
||||
return resolve(Array.prototype.slice.call(arguments, 1));
|
||||
}
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue