All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ubirch.kafka.util.Callback0.scala Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package com.ubirch.kafka.util

/**
  * Represents a simple callback data type that takes no parameters
  *
  * @tparam B Represents the output of the callback
  */
trait Callback0[B] {

  var callbacks = Vector.empty[() => B]

  def addCallback(f: () => B): Unit = {
    callbacks = callbacks ++ Vector(f)
  }

  def run(): Unit = callbacks.foreach(x => x())

}

/**
  * Represents a simple callback data type that takes one parameter of the A
  *
  * @tparam A Represents the input of the callback
  * @tparam B Represents the output of the callback
  */
trait Callback[A, B] extends {

  var callbacks = Vector.empty[A => B]

  def addCallback(f: A => B): Unit = {
    callbacks = callbacks ++ Vector(f)
  }

  def run(a: A): Vector[B] = callbacks.map(x => x(a))

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy