summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-28 07:21:00 +0200
commitdc04ca93060443a3ce6263a476f4dafc66afc6b3 (patch)
treeb9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js
parentUpdate config supports_message_history (diff)
downloadgpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.gz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.bz2
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.lz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.xz
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.zst
gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.zip
Diffstat (limited to 'g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js')
-rw-r--r--g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js b/g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js
new file mode 100644
index 00000000..2985c1ef
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/undici/lib/api/abort-signal.js
@@ -0,0 +1,54 @@
+const { addAbortListener } = require('../core/util')
+const { RequestAbortedError } = require('../core/errors')
+
+const kListener = Symbol('kListener')
+const kSignal = Symbol('kSignal')
+
+function abort (self) {
+ if (self.abort) {
+ self.abort()
+ } else {
+ self.onError(new RequestAbortedError())
+ }
+}
+
+function addSignal (self, signal) {
+ self[kSignal] = null
+ self[kListener] = null
+
+ if (!signal) {
+ return
+ }
+
+ if (signal.aborted) {
+ abort(self)
+ return
+ }
+
+ self[kSignal] = signal
+ self[kListener] = () => {
+ abort(self)
+ }
+
+ addAbortListener(self[kSignal], self[kListener])
+}
+
+function removeSignal (self) {
+ if (!self[kSignal]) {
+ return
+ }
+
+ if ('removeEventListener' in self[kSignal]) {
+ self[kSignal].removeEventListener('abort', self[kListener])
+ } else {
+ self[kSignal].removeListener('abort', self[kListener])
+ }
+
+ self[kSignal] = null
+ self[kListener] = null
+}
+
+module.exports = {
+ addSignal,
+ removeSignal
+}