Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: make fetch sync and return a Promise #49936

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ function setupUndici() {
}

if (!getOptionValue('--no-experimental-fetch')) {
async function fetch(input, init = undefined) {
// Fetch is meant to return a Promise, but not be async.
function fetch(input, init = undefined) {
return lazyUndici().fetch(input, init);
}

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ assert.strictEqual(typeof globalThis.Headers, 'function');
assert.strictEqual(typeof globalThis.Request, 'function');
assert.strictEqual(typeof globalThis.Response, 'function');

{
const asyncFunction = async function() {}.constructor;

assert.ok(!(fetch instanceof asyncFunction));
KhafraDev marked this conversation as resolved.
Show resolved Hide resolved
assert.notStrictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(async function() {}));
assert.strictEqual(Reflect.getPrototypeOf(fetch), Reflect.getPrototypeOf(function() {}));
}

const server = http.createServer(common.mustCall((req, res) => {
res.end('Hello world');
}));
Expand Down