This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Layer support to SerializedWorker (#354)
- Loading branch information
Showing
14 changed files
with
187 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@effect/platform-browser": patch | ||
"@effect/platform-node": patch | ||
"@effect/platform-bun": patch | ||
"@effect/platform": patch | ||
--- | ||
|
||
add Layer support to SerializedWorker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 17 additions & 22 deletions
39
packages/platform-browser/test/fixtures/serializedWorker.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,23 @@ | ||
import * as Runner from "@effect/platform-browser/WorkerRunner" | ||
import { Effect, Layer, Stream } from "effect" | ||
import { Context, Effect, Layer, Stream } from "effect" | ||
import { Person, User, WorkerMessage } from "./schema.js" | ||
|
||
const WorkerLive = Layer.scopedDiscard( | ||
Effect.gen(function*(_) { | ||
let name = "test" | ||
interface Name { | ||
readonly _: unique symbol | ||
} | ||
const Name = Context.Tag<Name, string>() | ||
|
||
yield* _( | ||
Runner.makeSerialized(WorkerMessage, { | ||
GetPersonById: (req) => | ||
Stream.make( | ||
new Person({ id: req.id, name: "test" }), | ||
new Person({ id: req.id, name: "ing" }) | ||
), | ||
GetUserById: (req) => Effect.succeed(new User({ id: req.id, name })), | ||
SetName: (req) => | ||
Effect.sync(() => { | ||
name = req.name | ||
}) | ||
}) | ||
) | ||
}) | ||
).pipe( | ||
Layer.provide(Runner.layerPlatform) | ||
) | ||
const WorkerLive = Runner.layerSerialized(WorkerMessage, { | ||
GetPersonById: (req) => | ||
Stream.make( | ||
new Person({ id: req.id, name: "test" }), | ||
new Person({ id: req.id, name: "ing" }) | ||
), | ||
GetUserById: (req) => Effect.map(Name, (name) => new User({ id: req.id, name })), | ||
SetName: (req) => Layer.succeed(Name, req.name) | ||
}) | ||
.pipe( | ||
Layer.provide(Runner.layerPlatform) | ||
) | ||
|
||
Effect.runFork(Layer.launch(WorkerLive)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.