TaskExtensions

portals.api.builder.TaskExtensions$

Task Extensions. Import extensions for more flexibility in building tasks.

Attributes

Example
import portals.api.builder.TaskExtensions.*
// imported filter TaskExtension
TaskBuilder.filter[Int]( event => event > 0 )
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

object VSMTasks

Behavior factories for VSM Tasks.

Behavior factories for VSM Tasks.

A VSMTask is a task that can be in one of several states. A state is a VSMTask instance. The methods of the VSMTask return the next VSMTask behavior to execute.

The VSM Tasks are used in a context with using the surrounding TaskBuilder.vsm behavior.

Attributes

See also

VSMTask

TaskBuilder.vsm wrapping initializing behavior.

Example
val init = VSMExtension.processor { event => started }
val started = VSMExtension.processor { event => init }
val vsm = TaskBuilder.vsm[Int, Int] { init }
Supertypes
class Object
trait Matchable
class Any
Self type
VSMTasks.type

Experimental classlikes

Attributes

Experimental
true
Supertypes
class Object
trait Matchable
class Any
Self type

Extensions

Extensions

extension (t: TaskBuilder)(t: TaskBuilder)
def filter[T](p: T => Boolean): GenericTask[T, T, Nothing, Nothing]

Filter events using the predicate p.

Filter events using the predicate p.

Attributes

def flatMap[T, U](f: MapTaskContext[T, U] ?=> T => IterableOnce[U]): GenericTask[T, U, Nothing, Nothing]

Behavior factory for flatMap.

Behavior factory for flatMap.

Map and flatten events of type T to events of type U.

Type parameters

T

type of the input events

U

type of the output events

Value parameters

f

the flatMap function

Attributes

Returns

the flatMap task

Example
TaskBuilder.flatMap[String, Int]( event => event.split(" ") )
def logger[T](prefix: String): GenericTask[T, T, Nothing, Nothing]

Log all events with the optional prefix.

Log all events with the optional prefix.

Attributes

extension (t: TaskBuilder)(t: TaskBuilder)
def vsm[T, U](defaultTask: VSMTask[T, U]): GenericTask[T, U, Nothing, Nothing]

Vsm behavior factory

Vsm behavior factory

The inner behavior should return the next state, for this we recommend the use of [VSMExtension.processor], note that the use of Tasks.processor will not work, as it returns Unit and not the next behavior. Warning: do not use vsm for the inner behavior, this will lead to an infinite loop and crash.

Example:

val init = VSMExtension.processor { event => started }
val started = VSMExtension.processor { event => init }
val vsm = VSMExtension.vsm[Int, Int] { init }

Attributes

extension [T, U, Req, Rep](task: GenericTask[T, U, Req, Rep])(task: GenericTask[T, U, Req, Rep])
def withOnAtomComplete(f: ProcessorTaskContext[T, U] ?=> Unit): GenericTask[T, U, Req, Rep]

Replace the onAtomComplete method of the task by f.

Replace the onAtomComplete method of the task by f.

Attributes

def withOnComplete(f: ProcessorTaskContext[T, U] ?=> Unit): GenericTask[T, U, Req, Rep]

Replace the onComplete method of the task by f.

Replace the onComplete method of the task by f.

Attributes

def withOnError(f: ProcessorTaskContext[T, U] ?=> Throwable => Unit): GenericTask[T, U, Req, Rep]

Replace the onError method of the task by f.

Replace the onError method of the task by f.

Attributes

def withOnNext(f: ProcessorTaskContext[T, U] ?=> T => Unit): GenericTask[T, U, Req, Rep]

Replace the onNext method of the task by f.

Replace the onNext method of the task by f.

Attributes

extension [T, U](task: GenericTask[T, U, Nothing, Nothing])(task: GenericTask[T, U, Nothing, Nothing])
def withLoop(count: Int)(_task: GenericTask[T, U, Nothing, Nothing]): GenericTask[T, U, Nothing, Nothing]

Behavior factory for looping behaviors over atoms. This will execute the provided _task for the following count atoms.

Behavior factory for looping behaviors over atoms. This will execute the provided _task for the following count atoms.

Value parameters

_task

the task to execute for the next count atoms

count

the number of loops/atoms to execute the _task for

Attributes

Returns

a looping task executing first the previous task and then _task for count iterations

Example
val task = TaskBuilder
 .map[String, String]{ event => event }
 .withLoop(2)(TaskBuilder.map[String, String]{ event => event.reverse })
def withStep(_task: GenericTask[T, U, Nothing, Nothing]): GenericTask[T, U, Nothing, Nothing]

Behavior factory for taking steps over atoms. This will execute the provided _task for the following atom subsequently to the current task.

Behavior factory for taking steps over atoms. This will execute the provided _task for the following atom subsequently to the current task.

Value parameters

_task

the task to execute for the next atom

Attributes

Returns

a stepping task executing first the prvious task and then _task

Example
val task = TaskBuilder
 .map[String, String]{ event => event }
 .withStep(TaskBuilder.map[String, String]{ event => event.reverse })
extension [T, U](task: GenericTask[T, U, Nothing, Nothing])(task: GenericTask[T, U, Nothing, Nothing])
def withAndThen[TT](_task: GenericTask[U, TT, Nothing, Nothing]): GenericTask[T, TT, Nothing, Nothing]

Chain a task with another _task, the tasks will share state.

Chain a task with another _task, the tasks will share state.

Type parameters

TT

the type of the output of the chained _task

Value parameters

_task

the task to execute after the current task

Attributes

Returns

a task executing first the previous task and then _task

Example
val task = TaskBuilder
 .map[String, String]{ event => event }
 .withAndThen(TaskBuilder.map[String, String]{ event => event.reverse })
extension [T, U](task: GenericTask[T, U, Nothing, Nothing])(task: GenericTask[T, U, Nothing, Nothing])
def withWrapper[V](f: ProcessorTaskContext[T, U | V] ?=> (ProcessorTaskContext[T, U | V] ?=> T => Unit) => T => Unit): GenericTask[T, U | V, _, _]

Wrapping around the behavior of a task. The wrapped behavior is accessible for use.

Wrapping around the behavior of a task. The wrapped behavior is accessible for use.

Example use:

Tasks.map[Int, Int] { _ + 5 }
 .withWrapper[String]{ ctx ?=> wrapped => event =>
   if event < 3 then ctx.emit("0") else wrapped(event)
 }

Type parameters

V

additional type for widening the output type of the task by union

Value parameters

f

the wrapping function to wrap around the behavior of the task

Attributes

Returns

a task with the wrapped behavior