@@ -323,9 +323,10 @@ class Sharding private (
323323 private def registerEntity [R , Req : Tag ](
324324 entityType : EntityType [Req ],
325325 behavior : (String , Dequeue [Req ]) => RIO [R , Nothing ],
326- terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None
326+ terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None ,
327+ entityMaxIdleTime : Option [Duration ] = None
327328 ): ZManaged [Clock with R , Nothing , Unit ] =
328- registerRecipient(entityType, behavior, terminateMessage) *>
329+ registerRecipient(entityType, behavior, terminateMessage, entityMaxIdleTime ) *>
329330 eventsHub.publish(ShardingRegistrationEvent .EntityRegistered (entityType)).unit.toManaged_
330331
331332 private def registerTopic [R , Req : Tag ](
@@ -341,10 +342,12 @@ class Sharding private (
341342 def registerRecipient [R , Req : Tag ](
342343 recipientType : RecipientType [Req ],
343344 behavior : (String , Dequeue [Req ]) => RIO [R , Nothing ],
344- terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None
345+ terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None ,
346+ entityMaxIdleTime : Option [Duration ] = None
345347 ): ZManaged [Clock with R , Nothing , Unit ] =
346348 for {
347- entityManager <- EntityManager .make(recipientType, behavior, terminateMessage, self, config).toManaged_
349+ entityManager <-
350+ EntityManager .make(recipientType, behavior, terminateMessage, self, config, entityMaxIdleTime).toManaged_
348351 binaryQueue <- Queue
349352 .unbounded[(BinaryMessage , Promise [Throwable , Option [Array [Byte ]]], Promise [Nothing , Unit ])]
350353 .toManaged(_.shutdown)
@@ -482,11 +485,12 @@ object Sharding {
482485 def registerEntity [R , Req : Tag ](
483486 entityType : EntityType [Req ],
484487 behavior : (String , Dequeue [Req ]) => RIO [R , Nothing ],
485- terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None
488+ terminateMessage : Promise [Nothing , Unit ] => Option [Req ] = (_ : Promise [Nothing , Unit ]) => None ,
489+ entityMaxIdleTime : Option [Duration ] = None
486490 ): ZManaged [Has [Sharding ] with R with Clock , Nothing , Unit ] =
487491 for {
488492 sharding <- ZIO .service[Sharding ].toManaged_
489- _ <- sharding.registerEntity[R , Req ](entityType, behavior, terminateMessage)
493+ _ <- sharding.registerEntity[R , Req ](entityType, behavior, terminateMessage, entityMaxIdleTime )
490494 } yield ()
491495
492496 /**
0 commit comments