File size: 2,249 Bytes
31e8457 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | /**
* @since 4.0.0
*/
import * as Context from "../../Context.ts"
import * as Data from "../../Data.ts"
import type * as Effect from "../../Effect.ts"
import type * as Socket from "./Socket.ts"
/**
* @since 4.0.0
* @category tags
*/
export class SocketServer extends Context.Service<SocketServer, {
readonly address: Address
readonly run: <R, E, _>(
handler: (socket: Socket.Socket) => Effect.Effect<_, E, R>
) => Effect.Effect<never, SocketServerError, R>
}>()("@effect/platform/SocketServer") {}
/**
* @since 4.0.0
* @category errors
*/
export const ErrorTypeId: ErrorTypeId = "@effect/platform/SocketServer/SocketServerError"
/**
* @since 4.0.0
* @category errors
*/
export type ErrorTypeId = "@effect/platform/SocketServer/SocketServerError"
/**
* @since 4.0.0
* @category errors
*/
export class SocketServerOpenError extends Data.TaggedError("SocketServerOpenError")<{
readonly cause: unknown
}> {
override get message(): string {
return "Open"
}
}
/**
* @since 4.0.0
* @category errors
*/
export class SocketServerUnknownError extends Data.TaggedError("SocketServerUnknownError")<{
readonly cause: unknown
}> {
override get message(): string {
return "Unknown"
}
}
/**
* @since 4.0.0
* @category errors
*/
export type SocketServerErrorReason = SocketServerOpenError | SocketServerUnknownError
/**
* @since 4.0.0
* @category errors
*/
export class SocketServerError extends Data.TaggedError("SocketServerError")<{
readonly reason: SocketServerErrorReason
}> {
constructor(props: {
readonly reason: SocketServerErrorReason
}) {
super({
...props,
cause: props.reason.cause
} as any)
}
/**
* @since 4.0.0
*/
readonly [ErrorTypeId]: ErrorTypeId = ErrorTypeId
/**
* @since 4.0.0
*/
override get message(): string {
return this.reason.message
}
}
/**
* @since 4.0.0
* @category models
*/
export type Address = UnixAddress | TcpAddress
/**
* @since 4.0.0
* @category models
*/
export interface TcpAddress {
readonly _tag: "TcpAddress"
readonly hostname: string
readonly port: number
}
/**
* @since 4.0.0
* @category models
*/
export interface UnixAddress {
readonly _tag: "UnixAddress"
readonly path: string
}
|