type Task[+A] = ((A) ⇒ com.thoughtworks.dsl.domains.task.TaskDomain @com.thoughtworks.dsl.Dsl.reset) ⇒ TaskDomain
The asynchronous task that supports exception handling, resource management, and is stack-safe.
- Source
- task.scala
A Task can be created from
for
-comprehension, where keywords.Each and keywords.Fork can be used together to asynchronously iterate collections. For example, the aboveconcatenateRemoteData
downloads and concatenates data from multiple URLs.import com.thoughtworks.dsl.comprehension._ import com.thoughtworks.dsl.keywords._ import com.thoughtworks.dsl.keywords.Shift._ import com.thoughtworks.dsl.domains.task.Task import java.net.URL def concatenateRemoteData(urls: List[URL], downloader: URL => Task[Vector[Byte]]): Task[Vector[Byte]] = { for { url <- Fork(urls) data <- downloader(url) byte <- Each(data) } yield byte }.as[Task[Vector[Byte]]]
A Task can be also created from Task.apply
def mockDownloader(url: URL) = Task { "mock data\n".getBytes.toVector }
A Task can be then converted to scala.concurrent.Future via Task.toFuture, in order to integrate into other frameworks. In this example, it's a
Future[Assertion]
required by org.scalatest.freespec.AsyncFreeSpec.val mockUrls = List(new URL("http://example.com/file1"), new URL("http://example.com/file2")) import org.scalatest.Assertion def assertion: Task[Assertion] = Task { !concatenateRemoteData(mockUrls, mockDownloader) should be("mock data\nmock data\n".getBytes.toVector) } Task.toFuture(assertion)
- Alphabetic
- By Inheritance
- Task
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
apply(v1: T1): R
- Definition Classes
- Function1
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
andThen[A](g: (R) ⇒ A): (T1) ⇒ A
- Definition Classes
- Function1
- Annotations
- @unspecialized()
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native() @HotSpotIntrinsicCandidate()
-
def
compose[A](g: (A) ⇒ T1): (A) ⇒ R
- Definition Classes
- Function1
- Annotations
- @unspecialized()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- Function1 → AnyRef → Any
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )