Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Singleton Scala actor?

Simple question. Can I do this:

object Xyz extends Actor { ... }

or do Actors have to be classes with instances?

like image 794
Joe Avatar asked Oct 22 '09 22:10

Joe


3 Answers

Object extending Actor works fine.

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

object Xyz extends Actor {
    start

    ...
}
like image 99
HRJ Avatar answered Oct 24 '22 04:10

HRJ


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.

like image 22
Lachlan Avatar answered Oct 24 '22 05:10

Lachlan


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

Actor.actor { doStuff }

Your operation will run in a separate thread to conclusion.

like image 2
Fred Haslam Avatar answered Oct 24 '22 05:10

Fred Haslam