scala - What does CallingThreadDispatcher do? -


i came across code , wonder callingthreaddispatcher does. can comment out

val dispatcherid = callingthreaddispatcher.id val props = props[greeter].withdispatcher(dispatcherid) 

and test still work

class greetertest extends testkit(testsystem)   wordspeclike   mustmatchers   stopsystemafterall {    "the greeter" must {     "say hello world! when greeting(\"world\") sent it" in {       val dispatcherid = callingthreaddispatcher.id       val props = props[greeter].withdispatcher(dispatcherid)       val greeter = system.actorof(props)       eventfilter.info(message = "hello world!", occurrences = 1).intercept {         greeter ! greeting("world")       }     }   } }  object greetertest {   val testsystem = {     val config = configfactory.parsestring("""akka.loggers = [akka.testkit.testeventlistener]""")     actorsystem("testsystem", config)   } } 

so callingthreaddispatcher do? , why need it?

the documentation callingthreaddispatcher pretty good:

* dispatcher runs invocations on current thread only. * dispatcher not create new threads, can used * different threads concurrently same actor. dispatch strategy * run on current thread unless target actor either suspendswitch or * running on current thread (if running on different * thread, thread block until other invocation * finished); if invocation not run, queued in thread-local * queue executed once active invocation further call stack * finishes. leads deterministic execution order if 1 * thread used. 

it used in unit tests because convenient actors have deterministic order of execution when you're testing particular unit of code. see, isn't mandatory test you're running , works without it.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -