Merge commit '3c60637c1a27da8ba66888de518d58d5707801f2' as 'repos/effect-smol'

This commit is contained in:
-Puter
2026-07-19 03:28:54 +05:30
parent 2daf979036
commit a37e0cc3c9
2163 changed files with 668421 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import { Effect, Schema, Stream } from "effect"
import { HttpClient, HttpClientResponse } from "effect/unstable/http"
import { HttpApi, HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi"
import { Bench } from "tinybench"
const Event = Schema.Struct({
event: Schema.Literal("tick"),
data: Schema.String
})
const Api = HttpApi.make("Api").add(
HttpApiGroup.make("test").add(
HttpApiEndpoint.get("events", "/events", {
success: HttpApiSchema.StreamSse({
events: Event,
error: Schema.String
})
})
)
)
const httpClient = HttpClient.make((request) =>
Effect.sync(() =>
HttpClientResponse.fromWeb(
request,
new Response("event: tick\ndata: payload\n\n", {
status: 200,
headers: { "content-type": "text/event-stream" }
})
)
)
)
const client = await Effect.runPromise(HttpApiClient.makeWith(Api, {
baseUrl: "http://localhost",
httpClient
}))
const consumeResponse = Effect.flatMap(client.test.events({}), Stream.runDrain)
const responsesPerIteration = 25
const responses = Array.from({ length: responsesPerIteration })
const runIteration = Effect.forEach(responses, () => consumeResponse, {
concurrency: 1,
discard: true
})
const bench = new Bench({ time: 3000 })
bench.add(`${responsesPerIteration} sequential SSE responses through one client`, () => Effect.runPromise(runIteration))
await bench.run()
console.table(bench.table())