Trait/Object

com.thoughtworks.dsl.keywords

AsynchronousIo

Related Docs: object AsynchronousIo | package keywords

Permalink

trait AsynchronousIo[Value] extends Keyword[AsynchronousIo[Value], Value]

The base keyword to perform asynchronous IO in domains.task.Tasks.

Source
AsynchronousIo.scala
Example:
  1. The following readAll is a Task to read file content with the help of AsynchronousIo.ReadFile

    import 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 in for-comprehension, and other keywords can be used together in the same for block. For example, the following cat function contains a single for block to concatenate file contents. It asynchronously iterates elements Seq, ArrayBuffer and String with the help of keywords.Each, managed native resources with the help of keywords.Using, performs previously created readAll task with the help of keywords.Shift, and finally converts the return type as a Task[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 cat function 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"
      )
    })
Linear Supertypes
Keyword[AsynchronousIo[Value], Value], Any
Known Subclasses
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. AsynchronousIo
  2. Keyword
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getClass(): Class[_]

    Permalink
    Definition Classes
    Any
  2. abstract def start[Attachment](attachment: Attachment, handler: CompletionHandler[Value, _ >: Attachment]): Unit

    Permalink

    Starts the asynchronous operations

    Starts the asynchronous operations

    Attributes
    protected

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def +(other: String): String

    Permalink
    Implicit information
    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
  4. def ->[B](y: B): (AsynchronousIo[Value], B)

    Permalink
    Implicit information
    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()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. final def apply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[AsynchronousIo[Value], Domain, Value]): Domain

    Permalink

    An alias to cpsApply.

    An alias to cpsApply.

    Definition Classes
    Keyword
    Annotations
    @inline()
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. final def cpsApply[Domain](handler: (Value) ⇒ Domain)(implicit dsl: Dsl[AsynchronousIo[Value], Domain, Value]): Domain

    Permalink
    Definition Classes
    Keyword
    Annotations
    @inline()
  9. def ensuring(cond: (AsynchronousIo[Value]) ⇒ Boolean, msg: ⇒ Any): AsynchronousIo[Value]

    Permalink
    Implicit information
    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
  10. def ensuring(cond: (AsynchronousIo[Value]) ⇒ Boolean): AsynchronousIo[Value]

    Permalink
    Implicit information
    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
  11. def ensuring(cond: Boolean, msg: ⇒ Any): AsynchronousIo[Value]

    Permalink
    Implicit information
    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
  12. def ensuring(cond: Boolean): AsynchronousIo[Value]

    Permalink
    Implicit information
    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
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  14. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    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()
  15. def hashCode(): Int

    Permalink
    Definition Classes
    Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. def toString(): String

    Permalink
    Definition Classes
    Any
  18. final def unary_!: Value

    Permalink
    Definition Classes
    Keyword
    Annotations
    @shift() @compileTimeOnly( ... )
  19. def [B](y: B): (AsynchronousIo[Value], B)

    Permalink
    Implicit information
    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

Inherited from Keyword[AsynchronousIo[Value], Value]

Inherited from Any

Inherited by implicit conversion any2stringadd from AsynchronousIo[Value] to any2stringadd[AsynchronousIo[Value]]

Inherited by implicit conversion StringFormat from AsynchronousIo[Value] to StringFormat[AsynchronousIo[Value]]

Inherited by implicit conversion Ensuring from AsynchronousIo[Value] to Ensuring[AsynchronousIo[Value]]

Inherited by implicit conversion ArrowAssoc from AsynchronousIo[Value] to ArrowAssoc[AsynchronousIo[Value]]

Ungrouped