Skip to content

Commit edaf82d

Browse files
workers from lib
1 parent c832c1d commit edaf82d

2 files changed

Lines changed: 5 additions & 39 deletions

File tree

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,14 @@
11
import { WorkerRunner } from "@effect/platform";
22
import { BrowserWorkerRunner } from "@effect/platform-browser";
3-
import { RuntimeLib, Service, SyncWorker } from "@local/client-lib";
3+
import { RuntimeLib, SyncWorker } from "@local/client-lib";
44
import { Effect, Layer } from "effect";
55

66
const WorkerLive = WorkerRunner.layerSerialized(SyncWorker.WorkerMessage, {
77
Bootstrap: (params) =>
88
Effect.gen(function* () {
9-
const { push, pull } = yield* Service.Sync;
10-
11-
const manager = yield* Service.WorkspaceManager;
12-
const temp = yield* Service.TempWorkspace;
13-
14-
yield* Effect.log(`Running workspace '${params.workspaceId}'`);
15-
16-
const workspace = yield* manager
17-
.getById({ workspaceId: params.workspaceId })
18-
.pipe(Effect.flatMap(Effect.fromNullable));
19-
20-
const tempUpdates = yield* temp.getById({
21-
workspaceId: workspace.workspaceId,
22-
});
23-
24-
if (tempUpdates !== undefined) {
25-
yield* push({
26-
workspaceId: workspace.workspaceId,
27-
snapshot: tempUpdates.snapshot,
28-
snapshotId: tempUpdates.snapshotId,
29-
});
30-
yield* Effect.log("Push sync completed");
31-
} else {
32-
yield* pull({ workspaceId: workspace.workspaceId });
33-
yield* Effect.log("Pull sync completed");
34-
}
35-
36-
return true;
37-
}).pipe(
38-
Effect.mapError((error) => `Bootstrap error: ${JSON.stringify(error)}`)
39-
),
9+
const worker = yield* SyncWorker.SyncWorker;
10+
return yield* worker.bootstrap(params);
11+
}),
4012
}).pipe(Layer.provide(BrowserWorkerRunner.layer));
4113

4214
RuntimeLib.runFork(WorkerRunner.launch(WorkerLive));

apps/client/src/workers/live.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,9 @@ const WorkerLive = WorkerRunner.layer((params: SyncWorker.LiveQuery) =>
77
Effect.scoped(
88
Effect.gen(function* () {
99
const worker = yield* SyncWorker.SyncWorker;
10-
yield* Effect.log("Startup live query connection");
11-
12-
yield* Effect.addFinalizer(() =>
13-
Effect.log("Closed live query connection")
14-
);
15-
1610
yield* Effect.fork(worker.liveSync({ workspaceId: params.workspaceId }));
1711
yield* Effect.never;
18-
}).pipe(Effect.mapError(() => "Live query error"))
12+
})
1913
)
2014
).pipe(Layer.provide(BrowserWorkerRunner.layer));
2115

0 commit comments

Comments
 (0)