EdgeAIG's picture
download
raw
2.24 kB
/**
* Runs the server side of the unstable Effect devtools socket protocol.
*
* Use this module when an integration needs to accept devtools clients over a
* `SocketServer`, decode newline-delimited JSON messages, and handle each
* connection with application-specific logic. It does not interpret spans or
* metrics itself; it gives handlers a typed surface for the telemetry described
* by `DevToolsSchema`.
*
* @since 4.0.0
*/
import * as Effect from "../../Effect.js";
import * as Queue from "../../Queue.js";
import * as Schema from "../../Schema.js";
import * as Stream from "../../Stream.js";
import * as Ndjson from "../encoding/Ndjson.js";
import * as Socket from "../socket/Socket.js";
import * as SocketServer from "../socket/SocketServer.js";
import * as DevToolsSchema from "./DevToolsSchema.js";
const RequestSchema = /*#__PURE__*/Schema.toCodecJson(DevToolsSchema.Request);
const ResponseSchema = /*#__PURE__*/Schema.toCodecJson(DevToolsSchema.Response);
/**
* Runs the devtools socket server.
*
* **Details**
*
* Each connection is decoded as NDJSON devtools protocol messages, `Ping`
* requests are answered with `Pong`, and all other requests are delivered
* through the `Client` passed to the handler.
*
* @category constructors
* @since 4.0.0
*/
export const run = /*#__PURE__*/Effect.fnUntraced(function* (handle) {
const server = yield* SocketServer.SocketServer;
return yield* server.run(Effect.fnUntraced(function* (socket) {
const responses = yield* Queue.unbounded();
const requests = yield* Queue.unbounded();
const client = {
queue: requests,
send: response => Queue.offer(responses, response).pipe(Effect.asVoid)
};
yield* Stream.fromQueue(responses).pipe(Stream.pipeThroughChannel(Ndjson.duplexSchemaString(Socket.toChannelString(socket), {
inputSchema: ResponseSchema,
outputSchema: RequestSchema
})), Stream.runForEach(request => request._tag === "Ping" ? Queue.offer(responses, {
_tag: "Pong"
}) : Queue.offer(requests, request)), Effect.ensuring(Queue.shutdown(responses).pipe(Effect.andThen(Queue.shutdown(requests)))), Effect.forkChild);
return yield* handle(client);
}));
});
//# sourceMappingURL=DevToolsServer.js.map

Xet Storage Details

Size:
2.24 kB
·
Xet hash:
c61b32d665d72e38cd1908165e9270cfe8ba31424ca43952afae01ae1b57a2e1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.