0.1.13 #18

Merged
Thilawyn merged 359 commits from next into master 2025-06-18 00:12:19 +02:00
3 changed files with 23 additions and 18 deletions
Showing only changes of commit 9e7b30fbb4 - Show all commits

View File

@@ -2,7 +2,7 @@ import { R } from "@/reffuse"
import { HttpClient } from "@effect/platform" import { HttpClient } from "@effect/platform"
import { Text } from "@radix-ui/themes" import { Text } from "@radix-ui/themes"
import { createFileRoute } from "@tanstack/react-router" import { createFileRoute } from "@tanstack/react-router"
import { Effect, Schema } from "effect" import { Console, Effect, Schema } from "effect"
import { Suspense, use } from "react" import { Suspense, use } from "react"
@@ -15,7 +15,8 @@ const Result = Schema.Tuple(Schema.String)
type Result = typeof Result.Type type Result = typeof Result.Type
function RouteComponent() { function RouteComponent() {
const promise = R.usePromiseScoped(HttpClient.HttpClient.pipe( const promise = R.usePromiseScoped(Effect.addFinalizer(() => Console.log("Cleanup")).pipe(
Effect.andThen(HttpClient.HttpClient),
Effect.flatMap(client => client.get("https://www.uuidtools.com/api/generate/v4")), Effect.flatMap(client => client.get("https://www.uuidtools.com/api/generate/v4")),
HttpClient.withTracerPropagation(false), HttpClient.withTracerPropagation(false),
Effect.flatMap(res => res.json), Effect.flatMap(res => res.json),

View File

@@ -1,6 +1,6 @@
import { R } from "@/reffuse" import { R } from "@/reffuse"
import { createFileRoute } from "@tanstack/react-router" import { createFileRoute } from "@tanstack/react-router"
import { DateTime, Effect, Ref, Schedule, Stream, SubscriptionRef } from "effect" import { Console, DateTime, Effect, Ref, Schedule, Stream, SubscriptionRef } from "effect"
const timeEverySecond = Stream.repeatEffectWithSchedule( const timeEverySecond = Stream.repeatEffectWithSchedule(
@@ -16,7 +16,11 @@ export const Route = createFileRoute("/time")({
function Time() { function Time() {
const timeRef = R.useMemo(DateTime.now.pipe(Effect.flatMap(SubscriptionRef.make))) const timeRef = R.useMemo(DateTime.now.pipe(Effect.flatMap(SubscriptionRef.make)))
R.useFork(Stream.runForEach(timeEverySecond, v => Ref.set(timeRef, v)), [timeRef])
R.useFork(Effect.addFinalizer(() => Console.log("Cleanup")).pipe(
Effect.andThen(Stream.runForEach(timeEverySecond, v => Ref.set(timeRef, v)))
), [timeRef])
const [time] = R.useRefState(timeRef) const [time] = R.useRefState(timeRef)

View File

@@ -270,15 +270,13 @@ export class Reffuse<R> {
const runFork = this.useRunFork() const runFork = this.useRunFork()
return React.useEffect(() => { return React.useEffect(() => {
const scope = runSync(Scope.make(options?.finalizerExecutionStrategy)) const scope = runSync(options?.scope
const fiber = runFork(Effect.provideService(effect, Scope.Scope, scope), options) ? Scope.fork(options.scope, options?.finalizerExecutionStrategy ?? ExecutionStrategy.sequential)
: Scope.make(options?.finalizerExecutionStrategy)
)
runFork(Effect.provideService(effect, Scope.Scope, scope), { ...options, scope })
return () => { return () => { runFork(Scope.close(scope, Exit.void)) }
Fiber.interrupt(fiber).pipe(
Effect.andThen(Scope.close(scope, Exit.void)),
runFork,
)
}
}, [ }, [
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync, runFork], ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync, runFork],
...(deps ?? []), ...(deps ?? []),
@@ -322,15 +320,17 @@ export class Reffuse<R> {
}), }),
// TODO: use scope from RunForkOptions? // TODO: use scope from RunForkOptions?
effect => runFork(effect, options), effect => runFork(effect, { ...options, scope }),
) )
return () => { return () => {
Fiber.interrupt(fiber).pipe( // Fiber.interrupt(fiber).pipe(
Effect.andThen(Scope.close(scope, Exit.void)), // Effect.andThen(Scope.close(scope, Exit.void)),
Effect.andThen(Effect.sync(() => { reject() })), // TODO: Relevant? // // \/ TODO: should interrupted promises reject?
runFork, // // Effect.andThen(Effect.sync(() => { reject() })),
) // runFork,
// )
runFork(Scope.close(scope, Exit.void))
} }
}, [ }, [
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync, runFork], ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync, runFork],