Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/scala.concurrent/BlockContext

BlockContext

scala.concurrent.BlockContext
See theBlockContext companion object

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}

Attributes

Companion
object
Source
BlockContext.scala
Graph
Supertypes
classObject
traitMatchable
classAny

Members list

Value members

Abstract methods

defblockOn[T](thunk:=>T)(implicitpermission:CanAwait):T

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.

Attributes

Throws

IllegalArgumentExceptionif thepermission isnull

Source
BlockContext.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp