mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
fix(adapter): fix progress event emitting; (#6518)
This commit is contained in:
+33
-1
@@ -669,6 +669,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
||||
const isThenable = (thing) =>
|
||||
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
||||
|
||||
// original code
|
||||
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
||||
|
||||
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
||||
if (setImmediateSupported) {
|
||||
return setImmediate;
|
||||
}
|
||||
|
||||
return postMessageSupported ? ((token, callbacks) => {
|
||||
_global.addEventListener("message", ({source, data}) => {
|
||||
if (source === _global && data === token) {
|
||||
callbacks.length && callbacks.shift()();
|
||||
}
|
||||
}, false);
|
||||
|
||||
return (cb) => {
|
||||
callbacks.push(cb);
|
||||
_global.postMessage(token, "*");
|
||||
}
|
||||
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
||||
})(
|
||||
typeof setImmediate === 'function',
|
||||
isFunction(_global.postMessage)
|
||||
);
|
||||
|
||||
const asap = typeof queueMicrotask !== 'undefined' ?
|
||||
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
||||
|
||||
// *********************
|
||||
|
||||
export default {
|
||||
isArray,
|
||||
isArrayBuffer,
|
||||
@@ -724,5 +754,7 @@ export default {
|
||||
isSpecCompliantForm,
|
||||
toJSONObject,
|
||||
isAsyncFn,
|
||||
isThenable
|
||||
isThenable,
|
||||
setImmediate: _setImmediate,
|
||||
asap
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user