开发者

Singleton Scala actor?

开发者 https://www.devze.com 2022-12-09 09:50 出处:网络
Sim开发者_如何学JAVAple question. Can I do this: object Xyz extends Actor { ... } or do Actors have to be classes with instances?Object extending Actor works fine.

Sim开发者_如何学JAVAple question. Can I do this:

object Xyz extends Actor { ... }

or do Actors have to be classes with instances?


Object extending Actor works fine.

Perhaps you forgot to start the actor? (That's a mistake I did initially)

object Xyz extends Actor {
    start

    ...
}


The object keyword is essentially creating an anonymous class and a single instance of that class. So yes, that code will be fine - Xyz will be a reference to an object that is an Actor.


I would like to recommend the following 'fire and forget' pattern:

Actor.actor { doStuff }

Your operation will run in a separate thread to conclusion.

0

精彩评论

暂无评论...
验证码 换一张
取 消