Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

How does event listening work? #114

@burakakca

Description

@burakakca

I'm using two ZIO scope blocks in my codebase one of them is for creating commands and the other for listening if an event published. When the command and the listener are in the same code block and run sequentially, there is no problem, but when they are run in different time intervals, the listening side does not receive information. How can I solve this?

There is a pub/sub mechanism or it's reading from the database?

Command code block like this example; https://github.com/hnaderi/edomata-example/blob/05609b7f54388dae89b9a925eea21b794db9fd39/core/src/main/scala/dev/hnaderi/example/Main.scala#L47

Listening code block

def mySink(app: Application[Task]) = ZSink.foreach((item: OutboxItem[Notification]) =>
  for {
    _ <- printLine("mySink: " + item)
    _ <- app.accounts.storage.outbox.markAsSent(item)
  } yield ()
)

def printOutbox(app: Application[Task]) = app.accounts.storage.outbox.read.toZStream().run(mySink(app))

ZIO.scoped {
 for {
   app <- Application[Task]().toScopedZIO
   _ <- printOutbox(app)
  } yield ()
 }..fork

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions