@whatwg-node/node-fetch 0.0.1-alpha-20221225160212-6d4b104 → 0.0.1-alpha-20221225172458-8684a84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +23 -5
  2. package/index.mjs +23 -5
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -54,9 +54,11 @@ class PonyfillAbortController {
54
54
  }
55
55
 
56
56
  function createController(desiredSize, readable) {
57
+ let enqueued = false;
57
58
  return {
58
59
  desiredSize,
59
60
  enqueue(chunk) {
61
+ enqueued = true;
60
62
  readable.push(chunk);
61
63
  },
62
64
  close() {
@@ -65,6 +67,9 @@ function createController(desiredSize, readable) {
65
67
  error(error) {
66
68
  readable.destroy(error);
67
69
  },
70
+ get enqueued() {
71
+ return enqueued;
72
+ }
68
73
  };
69
74
  }
70
75
  class PonyfillReadableStream {
@@ -101,14 +106,27 @@ class PonyfillReadableStream {
101
106
  });
102
107
  }
103
108
  else {
109
+ let waitingForPull = false;
104
110
  this.readable = new stream.Readable({
105
- read(desiredSize) {
111
+ async read(desiredSize) {
106
112
  var _a, _b;
107
- if (!started) {
108
- started = true;
109
- (_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, createController(desiredSize, this));
113
+ if (waitingForPull) {
114
+ return;
115
+ }
116
+ waitingForPull = true;
117
+ try {
118
+ const controller = createController(desiredSize, this);
119
+ if (!started) {
120
+ started = true;
121
+ await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
122
+ }
123
+ if (!controller.enqueued) {
124
+ await ((_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, controller));
125
+ }
126
+ }
127
+ finally {
128
+ waitingForPull = false;
110
129
  }
111
- (_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, createController(desiredSize, this));
112
130
  },
113
131
  async destroy(err, callback) {
114
132
  var _a;
package/index.mjs CHANGED
@@ -50,9 +50,11 @@ class PonyfillAbortController {
50
50
  }
51
51
 
52
52
  function createController(desiredSize, readable) {
53
+ let enqueued = false;
53
54
  return {
54
55
  desiredSize,
55
56
  enqueue(chunk) {
57
+ enqueued = true;
56
58
  readable.push(chunk);
57
59
  },
58
60
  close() {
@@ -61,6 +63,9 @@ function createController(desiredSize, readable) {
61
63
  error(error) {
62
64
  readable.destroy(error);
63
65
  },
66
+ get enqueued() {
67
+ return enqueued;
68
+ }
64
69
  };
65
70
  }
66
71
  class PonyfillReadableStream {
@@ -97,14 +102,27 @@ class PonyfillReadableStream {
97
102
  });
98
103
  }
99
104
  else {
105
+ let waitingForPull = false;
100
106
  this.readable = new Readable({
101
- read(desiredSize) {
107
+ async read(desiredSize) {
102
108
  var _a, _b;
103
- if (!started) {
104
- started = true;
105
- (_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, createController(desiredSize, this));
109
+ if (waitingForPull) {
110
+ return;
111
+ }
112
+ waitingForPull = true;
113
+ try {
114
+ const controller = createController(desiredSize, this);
115
+ if (!started) {
116
+ started = true;
117
+ await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
118
+ }
119
+ if (!controller.enqueued) {
120
+ await ((_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, controller));
121
+ }
122
+ }
123
+ finally {
124
+ waitingForPull = false;
106
125
  }
107
- (_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, createController(desiredSize, this));
108
126
  },
109
127
  async destroy(err, callback) {
110
128
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.0.1-alpha-20221225160212-6d4b104",
3
+ "version": "0.0.1-alpha-20221225172458-8684a84",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {