Example of using `SocketServer` with Node.js
Are there any examples for using
Tried a basic example but ran into errors:
SocketServerSocketServer?Tried a basic example but ran into errors:
import { Effect, Layer, pipe } from "effect";
import { SocketServer } from "@effect/experimental";
import * as NodeSocketServer from "@effect/experimental/SocketServer/Node";
import { NodeRuntime } from "@effect/platform-node";
const RunLive = Layer.effectDiscard( // side note is there a Layer.effectDiscardScoped
Effect.gen(function* () {
const server = yield* SocketServer.SocketServer;
yield* server.run((socket) =>
Effect.gen(function* () {
yield* Effect.log("Connected");
const writer = yield* socket.writer;
yield* socket.run((messaage) => writer(messaage));
})
);
}).pipe(Effect.scoped)
);
pipe(
RunLive,
Layer.provide(NodeSocketServer.layer({ port: 3002 })),
Layer.launch,
NodeRuntime.runMain
);import { Effect, Layer, pipe } from "effect";
import { SocketServer } from "@effect/experimental";
import * as NodeSocketServer from "@effect/experimental/SocketServer/Node";
import { NodeRuntime } from "@effect/platform-node";
const RunLive = Layer.effectDiscard( // side note is there a Layer.effectDiscardScoped
Effect.gen(function* () {
const server = yield* SocketServer.SocketServer;
yield* server.run((socket) =>
Effect.gen(function* () {
yield* Effect.log("Connected");
const writer = yield* socket.writer;
yield* socket.run((messaage) => writer(messaage));
})
);
}).pipe(Effect.scoped)
);
pipe(
RunLive,
Layer.provide(NodeSocketServer.layer({ port: 3002 })),
Layer.launch,
NodeRuntime.runMain
);import { Effect, Layer, pipe } from "effect";
import { NodeRuntime, NodeSocket } from "@effect/platform-node";
import { Socket } from "@effect/platform";
const main = Effect.gen(function* () {
const socket = yield* Socket.Socket;
const writer = yield* socket.writer;
yield* socket.run((message) => Effect.log(message));
yield* writer("Hello World");
}).pipe(Effect.scoped);
pipe(
main,
Effect.provide(NodeSocket.layerWebSocket("ws://localhost:3002")),
NodeRuntime.runMain
);import { Effect, Layer, pipe } from "effect";
import { NodeRuntime, NodeSocket } from "@effect/platform-node";
import { Socket } from "@effect/platform";
const main = Effect.gen(function* () {
const socket = yield* Socket.Socket;
const writer = yield* socket.writer;
yield* socket.run((message) => Effect.log(message));
yield* writer("Hello World");
}).pipe(Effect.scoped);
pipe(
main,
Effect.provide(NodeSocket.layerWebSocket("ws://localhost:3002")),
NodeRuntime.runMain
);[15:54:08.942] INFO (#3): Unhandled error in SocketServer handler
TypeError: conn.destroySoon is not a function. (In 'conn.destroySoon()', 'conn.destroySoon' is undefined)
at <anonymous> (/node_modules/@effect/experimental/dist/esm/SocketServer/Node.js:47:16)[15:54:08.942] INFO (#3): Unhandled error in SocketServer handler
TypeError: conn.destroySoon is not a function. (In 'conn.destroySoon()', 'conn.destroySoon' is undefined)
at <anonymous> (/node_modules/@effect/experimental/dist/esm/SocketServer/Node.js:47:16)