Class in Client and Lifecycle · Effect API
Effect service holding one native client, for applications that assemble their program from Layers
class FluxerClientBuild it with FluxerClient.layer(options) or Fluxer(options), and read it with yield* FluxerClient or FluxerClient.use. The layer creates the client in the layer's Scope and calls shutdown when that Scope closes, awaiting SDK cleanup. Building the layer does not connect the gateway or make a request
Register handlers first, then call client.connect() or client.run(), so no event arrives before its handler exists. HTTP operations work without connecting. Each build of the layer creates its own client. Provide one layer value to share its client, since Effect reuses a layer value within one provide. The service holds the full Message shape
For a messageFields selection, call createClient directly instead
import { Config, Effect } from "effect"
import { FluxerClient } from "@neontechspace/fluxerly/effect"
const program = Effect.gen(function* () {
const client = yield* FluxerClient
yield* client.on("messageCreate", (message) =>
message.content === "!ping"
? client.messages.reply(message, { content: "Pong!" }).pipe(Effect.asVoid)
: Effect.void,
)
yield* client.run()
})
export const main = program.pipe(
Effect.scoped,
Effect.provide(FluxerClient.layerConfig({ token: Config.Redacted("FLUXER_BOT_TOKEN") })),
)
Constructor#
Methods#
static layer#
Build the FluxerClient service from createClient settings
Invalid settings, including a missing or blank token, are misuse and the layer dies with ConfigurationError. Services required by the settings, such as those of an onError hook, become the layer's requirements, and native logging uses the Effect logger in effect where the layer is built. The client is created without connecting and is shut down when the layer's Scope closes
static layer<
E = never, R = never
>(options: ClientOptions<E, R>): Layer<FluxerClient, never, R>static layer<E = never, R = never>(
options: ClientOptions<E, R>
): Layer<FluxerClient, never, R>Parameters
options-
ClientOptions<E, R>
- Returns
Layer<FluxerClient, never, R>
static layerConfig #
Build the FluxerClient service from settings that may be read from Effect Config, such as { token: Config
Config values are read from the current ConfigProvider, by default the process environment, when the layer is built. A missing or unparsable Config value fails the layer with ConfigError before any client exists. A token that is present but blank, or another invalid setting, is misuse and the layer dies with ConfigurationError, as in FluxerClient.layer
The token stays Redacted until the client receives it and is never logged. The client is created without connecting and is shut down when the layer's Scope closes
static layerConfig<E = never, R = never>(
options: FluxerClientConfigOptions<E, R>
): Layer<FluxerClient, ConfigError, R>static layerConfig<
E = never, R = never
>(
options:
FluxerClientConfigOptions<E, R>
): Layer<
FluxerClient, ConfigError, R
>Parameters
options-
FluxerClientConfigOptions<E, R>
- Returns
Layer<FluxerClient, ConfigError, R>