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

Errors on Node.js v22.2 #20

Open
sntran opened this issue Jul 17, 2024 · 0 comments
Open

Errors on Node.js v22.2 #20

sntran opened this issue Jul 17, 2024 · 0 comments

Comments

@sntran
Copy link

sntran commented Jul 17, 2024

Using the following example (modified from the example on Cloudflare TCP Socket page

import { connect } from "@arrowood.dev/socket";

const decoder = new TextDecoder();

async function fetch(request) {
  const gopherAddr = { hostname: "gopher.floodgap.com", port: 70 };
  const url = new URL(request.url);

  try {
    const socket = connect(gopherAddr);

    const writer = socket.writable.getWriter();
    const encoder = new TextEncoder();
    const encoded = encoder.encode(url.pathname + "\r\n");
    await writer.write(encoded);

    return new Response(socket.readable, {
      headers: { "Content-Type": "text/plain" },
    });
  } catch (error) {
    console.log("error", error);
    return new Response("Socket connection failed: " + error, { status: 500 });
  }
}

const response = await fetch(new Request("gopher://gopher.floodgap.com/"));

for await (const chunk of response.body) {
  // console.log(decoder.decode(chunk));
}

When run against Node.js 22.2, error occurs:

$ $ node --version
v22.2.0
$ node test.js
Warning: Detected unsettled top-level await at file:///Users/sntran/Projects/@sntran/socket/test.js:28
for await (const chunk of response.body) {
                 ^

Works fine on Node.js 20.x and 18.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant