Urara-Blog/node_modules/.pnpm-store/v3/files/26/9ca128ebcfa34946f1177799dd722762bb497e5840c082167bcbd4455316f846fe6bec0373ca3c9be6c241b691037ea7b63b69a98a644bec98a043362a6e28
2022-08-14 01:14:53 +08:00

32 lines
860 B
Text

'use strict'
// We include a version number for the Dispatcher API. In case of breaking changes,
// this version number must be increased to avoid conflicts.
const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
const { InvalidArgumentError } = require('./core/errors')
const Agent = require('./agent')
if (getGlobalDispatcher() === undefined) {
setGlobalDispatcher(new Agent())
}
function setGlobalDispatcher (agent) {
if (!agent || typeof agent.dispatch !== 'function') {
throw new InvalidArgumentError('Argument agent must implement Agent')
}
Object.defineProperty(globalThis, globalDispatcher, {
value: agent,
writable: true,
enumerable: false,
configurable: false
})
}
function getGlobalDispatcher () {
return globalThis[globalDispatcher]
}
module.exports = {
setGlobalDispatcher,
getGlobalDispatcher
}