11import { NotFoundError } from "@/errors.js"
2- import { BlogPostRepo , Operations } from "@/services.js"
2+ import { BlogPostRepo , Events , Operations } from "@/services.js"
33import { BlogPost } from "@effect-app-boilerplate/models/Blog"
44import { BlogRsc } from "@effect-app-boilerplate/resources"
5+ import { BogusEvent } from "@effect-app-boilerplate/resources/Events"
56import { PositiveInt } from "@effect-app/prelude/schema"
67
78const { controllers, matchWithServices } = matchFor ( BlogRsc )
@@ -27,8 +28,8 @@ const CreatePost = matchWithServices("CreatePost")(
2728)
2829
2930const PublishPost = matchWithServices ( "PublishPost" ) (
30- { BlogPostRepo, Operations } ,
31- ( req , { BlogPostRepo, Operations } ) =>
31+ { BlogPostRepo, Events , Operations } ,
32+ ( req , { BlogPostRepo, Events , Operations } ) =>
3233 Do ( $ => {
3334 $ (
3435 BlogPostRepo . find ( req . id )
@@ -44,7 +45,7 @@ const PublishPost = matchWithServices("PublishPost")(
4445 const done : string [ ] = [ ]
4546
4647 const operationId = $ (
47- Effect . forkOperation (
48+ Effect . forkOperationWithEffect (
4849 opId =>
4950 Operations . update ( opId , {
5051 total : PositiveInt ( targets . length ) ,
@@ -61,7 +62,12 @@ const PublishPost = matchWithServices("PublishPost")(
6162 )
6263 . delay ( Duration . seconds ( 4 ) )
6364 )
64- . map ( ( ) => "the answer to the universe is 41" )
65+ . map ( ( ) => "the answer to the universe is 41" ) ,
66+ // while operation is running...
67+ _opId =>
68+ Effect . suspendSucceed ( ( ) => Events . publish ( new BogusEvent ( { } ) ) )
69+ . delay ( DUR . seconds ( 1 ) )
70+ . forever
6571 )
6672 )
6773
0 commit comments