source: node_modules/undici/lib/global.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 860 bytes
Line 
1'use strict'
2
3// We include a version number for the Dispatcher API. In case of breaking changes,
4// this version number must be increased to avoid conflicts.
5const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
6const { InvalidArgumentError } = require('./core/errors')
7const Agent = require('./agent')
8
9if (getGlobalDispatcher() === undefined) {
10 setGlobalDispatcher(new Agent())
11}
12
13function setGlobalDispatcher (agent) {
14 if (!agent || typeof agent.dispatch !== 'function') {
15 throw new InvalidArgumentError('Argument agent must implement Agent')
16 }
17 Object.defineProperty(globalThis, globalDispatcher, {
18 value: agent,
19 writable: true,
20 enumerable: false,
21 configurable: false
22 })
23}
24
25function getGlobalDispatcher () {
26 return globalThis[globalDispatcher]
27}
28
29module.exports = {
30 setGlobalDispatcher,
31 getGlobalDispatcher
32}
Note: See TracBrowser for help on using the repository browser.