trait AsynchronousIo[Value] extends Keyword[AsynchronousIo[Value], Value]
The base keyword to perform asynchronous IO in domains.task.Tasks.
- Source
- AsynchronousIo.scala
The following
readAllis a Task to read file content with the help of AsynchronousIo.ReadFileimport java.nio._, file._, channels._ import com.thoughtworks.dsl.domains.task.Task import com.thoughtworks.dsl.keywords._ import com.thoughtworks.dsl.keywords.Shift._ import com.thoughtworks.dsl.keywords.AsynchronousIo.ReadFile import scala.collection.mutable.ArrayBuffer import scala.io.Codec def readAll(channel: AsynchronousFileChannel, temporaryBufferSize: Int = 4096): Task[ArrayBuffer[CharBuffer]] = Task { val charBuffers = ArrayBuffer.empty[CharBuffer] val decoder = Codec.UTF8.decoder val byteBuffer = ByteBuffer.allocate(temporaryBufferSize) var position: Long = 0L while (!ReadFile(channel, byteBuffer, position) != -1) { position += byteBuffer.position() byteBuffer.flip() charBuffers += decoder.decode(byteBuffer) byteBuffer.clear() } charBuffers }
Tasks created from !-notation can be used infor-comprehension, and other keywords can be used together in the sameforblock. For example, the followingcatfunction contains a singleforblock to concatenate file contents. It asynchronously iterates elementsSeq,ArrayBufferandStringwith the help of keywords.Each, managed native resources with the help of keywords.Using, performs previously createdreadAlltask with the help of keywords.Shift, and finally converts the return type as aTask[Vector[Char]].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 cat(paths: Path*) = { for { path <- Each(paths) channel <- Using(AsynchronousFileChannel.open(path)) charBuffers <- readAll(channel) charBuffer <- Each(charBuffers) char <- Each(charBuffer.toString) } yield char }.as[Task[Vector[Char]]]
Then the
catfunction is used to concatenate files from this project, as shown below:Task.toFuture(Task { (!cat(Paths.get(".sbtopts"), Paths.get(".scalafmt.conf"))).mkString should be( "-J-XX:MaxMetaspaceSize=512M\n-J-Xmx5G\n-J-Xss6M\nversion = \"1.5.1\"\nmaxColumn = 120" ) })
- Alphabetic
- By Inheritance
- AsynchronousIo
- Keyword
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
getClass(): Class[_]
- Definition Classes
- Any
-
abstract
def
start[Attachment](attachment: Attachment, handler: CompletionHandler[Value, _ >: Attachment]): Unit
Starts the asynchronous operations
Starts the asynchronous operations
- Attributes
- protected
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
def
+(other: String): String
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to any2stringadd[AsynchronousIo[Value]] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): (AsynchronousIo[Value], B)
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to ArrowAssoc[AsynchronousIo[Value]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
apply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[AsynchronousIo[Value], Domain, Value]): Domain
An alias to cpsApply.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
final
def
cpsApply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[AsynchronousIo[Value], Domain, Value]): Domain
- Definition Classes
- Keyword
- Annotations
- @inline()
-
def
ensuring(cond: (AsynchronousIo[Value]) ⇒ Boolean, msg: ⇒ Any): AsynchronousIo[Value]
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to Ensuring[AsynchronousIo[Value]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: (AsynchronousIo[Value]) ⇒ Boolean): AsynchronousIo[Value]
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to Ensuring[AsynchronousIo[Value]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): AsynchronousIo[Value]
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to Ensuring[AsynchronousIo[Value]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): AsynchronousIo[Value]
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to Ensuring[AsynchronousIo[Value]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
equals(arg0: Any): Boolean
- Definition Classes
- Any
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to StringFormat[AsynchronousIo[Value]] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
def
hashCode(): Int
- Definition Classes
- Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
toString(): String
- Definition Classes
- Any
- final def unary_!: Value
-
def
→[B](y: B): (AsynchronousIo[Value], B)
- Implicit
- This member is added by an implicit conversion from AsynchronousIo[Value] to ArrowAssoc[AsynchronousIo[Value]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc