I'm trying to wrap some actor receive code in db transaction to build idempotent persistent view that handles events by updating the information in database.
class TrajectoryView extends IdempotentView {
override def viewId: String = "trajectoryView"
override def persistenceId: String = "sample-id-1"
override def handleEvent(event: Event): Unit = {
case ProcessDetectedEvent(time, processData, id, activityType) =>
val coords = Db.save(processData.coordinates)
Db.save(CoordinatesWrapper(id, coords))
case ProcessUpdatedEvent(id, processData, time) =>
val coords = Db.save(processData.coordinates)
Db.save(CoordinatesWrapper(id, coords))
}
}
abstract class IdempotentView extends PersistentView {
def handleEvent(event: Event): Unit = ???
var maxSeenSeqNumber = Db.query[SeqNumberWrapper].fetchOne().getOrElse(SeqNumberWrapper(0, viewId)).seqNumber
def receive: Receive = {
case event: Event =>
if (lastSequenceNr > maxSeenSeqNumber) {
Db.transaction {
Db.save(SeqNumberWrapper(lastSequenceNr, viewId))
handleEvent(event)
}
}
case _: Unit =>
println("Unknown message")
}
}
Error:(22, 50) missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: Unit override def handleEvent(event: Event): Unit = {
What should I do? I don't event understand what this error means exactly. From my point of view I have written all types, the compiler doesn't need to infer anything.
Choose one of
override def handleEvent: Event => Unit = {
...
}
or
override def handleEvent(event: Event): Unit = event match {
...
}
If more precisely your code inside braces is suitable for defining PartialFunction[T,Unit]
which is convertible to Unit
. So generally your code is correct, but compiler could not infer type T
and whines about it. But if it could result would be a function returning another function and not what you are expecting.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.