Skip to content

Instantly share code, notes, and snippets.

View titouancreach's full-sized avatar

Titouan CREACH titouancreach

  • Lorient, France
  • 06:45 (UTC +01:00)
View GitHub Profile
{
"egen": {
"prefix": "egen",
"body": [
"Effect.gen(function* () {",
" $0",
"})"
],
"description": "Effect.gen"
},
import { NodeRuntime } from '@effect/platform-node'
import { Database } from '@repo/shared/Database'
import { SqsService } from '@repo/shared/SqsService'
import { Config, Effect, Layer, LogLevel, Logger } from 'effect'
import { withMinimumLogLevel } from 'effect/Logger'
import * as DemoMessageConsumer from './Features/Demo/DemoMessageConsumer'
const consumers = [DemoMessageConsumer.consumer]
const dependencies = Layer.mergeAll(
import { Schema } from '@effect/schema'
import { SqsService, type QueueMessage } from '@repo/shared/SqsService'
import { Duration, Effect, Schedule } from 'effect'
const defaultAwsRetryPolicy = Schedule.intersect(
Schedule.exponential(Duration.seconds(1)),
Schedule.recurs(5),
)
export const makeConsumer = <A, I, E, R>({
queueName,
import {
CreateQueueCommand,
DeleteMessageCommand,
ReceiveMessageCommand,
SendMessageCommand,
type CreateQueueCommandInput,
} from '@aws-sdk/client-sqs'
import { Schema } from '@effect/schema'
import {
Array,
import { SQSClient } from '@aws-sdk/client-sqs'
import { Config, Context, Effect, Layer } from 'effect'
const makeSqsClient = Effect.gen(function* () {
const awsAccessKeyId = yield* Config.string('AWS_ACCESS_KEY_ID').pipe(
Config.withDescription('AWS Access Key ID'),
)
const awsSecretAccessKey = yield* Config.string('AWS_SECRET_ACCESS_KEY').pipe(
Config.withDescription('AWS Secret'),
)
const useMediaRecorder = () => {
const [mediaRecorder, setMediaRecorder] = useState<
Option.Option<Either.Either<MediaRecorder, UnknownException>>
>(Option.none());
const [queue] = useState(() => Effect.runSync(Queue.unbounded<BlobEvent>()));
const cbRef = useRef(Option.none());
useEffect(() => {
type StateMachine = Data.TaggedEnum<{
Recording: {
stream: Stream.Stream<BlobEvent>,
mediaRecorder: MediaRecorder
};
Stoped: {};
}>;
export function TranscribeWhisper({ className }: { className?: string }) {
const { Stoped, Recording, $match, $is } = Data.taggedEnum<StateMachine>();

hook-form / effect-ts resolver thread

Hello, When we use a schema with a non-symmetrical transformation like this one

const Schema = S.Struct({
  createdAt: S.DateFromString
})
port { Chunk, Console, Context, Effect, Layer, Stream } from "effect";
import amqp from "amqplib";
import { NodeRuntime } from "@effect/platform-node";
const make = Effect.gen(function* () {
const connection = yield* Effect.tryPromise(() =>
amqp.connect(
"amqps://***",
),
);
return yield* pipe(
// out
Stream.fromQueue(queue),
Stream.ensuring(Effect.zip(Queue.shutdown(queue), Console.log("Ending")), // Here I would be able to remove the "current" client from the current map of client
Stream.pipeThroughChannel(Socket.toChannel(socket)),
// in
Stream.decodeText(),
Stream.runForEach((message) =>
Effect.gen(function* () {