datasourcex-kotlin

Provides an API for binding Kotlin Coroutines, i.e. suspending functions and Flow, to subjects and channels provided by Caplin DataSource.

See also

Samples

dataSource.bind {
  to("my-service") {
    active {
      record {
        path(
            path = "/example/activeSubject",
            publisher =
                flow {
                  var count = 0
                  while (true) {
                    emit(mapOf("Count" to "${count++}"))
                    delay(1.seconds)
                  }
                },
        )
      }

      json {
        pattern(
            pattern = "/{username}/example/subjectPattern/{myKey}",
            configure = { objectMappings = mapOf("username" to "%u") },
        ) { _, parameters ->
          val username: String by parameters
          val myKey: String by parameters
          flow {
            var count = 0
            while (true) {
              emit(JsonObject("$username $myKey ${count++}"))
              delay(1.seconds)
            }
          }
        }
      }
    }
  }
}

Packages