Error when making HTTP server a WebSocket client: Type mismatch in Effect argument

Hi. I'm trying to get my HTTP Server to also be a Websocket Client:

import { HttpApiBuilder, HttpMiddleware } from '@effect/platform'
import { BunHttpServer, BunRuntime } from '@effect/platform-bun'
import { Effect, Layer, Logger, pipe } from 'effect'
import { UniswapWebSocketService } from '../service/UniswapWebSocketService'
import { ApiLive } from './Api'
import { TodosRepository } from './TodosRepository'

const initializeWebSocket = Effect.gen(function* ($) {
  const uniswap = yield* $(UniswapWebSocketService)
  yield* $(Effect.log('Initializing WebSocket connection...'))
  yield* $(uniswap.connect())
  yield* $(Effect.log('WebSocket connection initialized'))

  return Effect.gen(function* ($) {
    yield* $(Effect.log('Cleaning up WebSocket connection...'))
    yield* $(uniswap.disconnect())
    yield* $(Effect.log('WebSocket connection cleaned up'))
  })
})

const HttpLive = HttpApiBuilder.serve(HttpMiddleware.logger).pipe(
  Layer.provide(Logger.pretty),
  Layer.provide(ApiLive),
  Layer.provide(TodosRepository.Default),
  Layer.provide(UniswapWebSocketService.Live),
  Layer.provide(
    BunHttpServer.layer({
      port: 3000,
      hostname: '0.0.0.0',
    }),
  ),
)

const program = Effect.gen(function* ($) {
  const cleanup = yield* $(initializeWebSocket)
  const server = yield* $(Layer.launch(HttpLive))
  yield* $(
    Effect.ensuring(
      server,
      Effect.provide(cleanup, UniswapWebSocketService.Live),
    ),
  )
})

pipe(program, BunRuntime.runMain)


But it gives me the error:
Argument of type 'Effect<void, unknown, unknown>' is not assignable to parameter of type 'Effect<unknown, unknown, never>'.
  Type 'unknown' is not assignable to type 'never'.ts(2345)
Was this page helpful?