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
|
Rev | Line | |
---|
[d24f17c] | 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.
|
---|
| 5 | const globalDispatcher = Symbol.for('undici.globalDispatcher.1')
|
---|
| 6 | const { InvalidArgumentError } = require('./core/errors')
|
---|
| 7 | const Agent = require('./agent')
|
---|
| 8 |
|
---|
| 9 | if (getGlobalDispatcher() === undefined) {
|
---|
| 10 | setGlobalDispatcher(new Agent())
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | function 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 |
|
---|
| 25 | function getGlobalDispatcher () {
|
---|
| 26 | return globalThis[globalDispatcher]
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | module.exports = {
|
---|
| 30 | setGlobalDispatcher,
|
---|
| 31 | getGlobalDispatcher
|
---|
| 32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.