A context to be notified byscala.concurrent.blocking when a thread is about to block. In effect this trait provides the implementation forscala.concurrent.Await.scala.concurrent.Await.result andscala.concurrent.Await.ready locates an instance ofBlockContext by first looking for one provided throughBlockContext.withBlockContext and failing that, checking whetherThread.currentThread is an instance ofBlockContext. So a thread pool can have itsjava.lang.Thread instances implementBlockContext. There's a defaultBlockContext used if the thread doesn't implementBlockContext.
Typically, you'll want to chain to the previousBlockContext, like this:
val oldContext = BlockContext.currentval myContext = new BlockContext { override def blockOn[T](thunk: => T)(implicit permission: CanAwait): T = { // you'd have code here doing whatever you need to do // when the thread is about to block. // Then you'd chain to the previous context: oldContext.blockOn(thunk) }}BlockContext.withBlockContext(myContext) { // then this block runs with myContext as the handler // for scala.concurrent.blocking}Used internally by the framework; Designates (and eventually executes) a thunk which potentially blocks the callingjava.lang.Thread.
Used internally by the framework; Designates (and eventually executes) a thunk which potentially blocks the callingjava.lang.Thread.
Clients must usescala.concurrent.blocking orscala.concurrent.Await instead.
In implementations of this method it is RECOMMENDED to first check ifpermission isnull and if it is, throw anIllegalArgumentException.
IllegalArgumentExceptionif thepermission isnull