gordonmu-coio

A library for a simple coroutine IO API, wrapping efficient non-blocking Java IO libs for easy use.

License

License

GroupId

GroupId

io.github.gordonmu
ArtifactId

ArtifactId

gordonmu-coio
Last Version

Last Version

0.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

gordonmu-coio
A library for a simple coroutine IO API, wrapping efficient non-blocking Java IO libs for easy use.
Project URL

Project URL

https://github.com/gordonmu/coio
Source Code Management

Source Code Management

https://github.com/gordonmu/coio

Download gordonmu-coio

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.gordonmu/gordonmu-coio/ -->
<dependency>
    <groupId>io.github.gordonmu</groupId>
    <artifactId>gordonmu-coio</artifactId>
    <version>0.8.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.gordonmu/gordonmu-coio/
implementation 'io.github.gordonmu:gordonmu-coio:0.8.0'
// https://jarcasting.com/artifacts/io.github.gordonmu/gordonmu-coio/
implementation ("io.github.gordonmu:gordonmu-coio:0.8.0")
'io.github.gordonmu:gordonmu-coio:jar:0.8.0'
<dependency org="io.github.gordonmu" name="gordonmu-coio" rev="0.8.0">
  <artifact name="gordonmu-coio" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.gordonmu', module='gordonmu-coio', version='0.8.0')
)
libraryDependencies += "io.github.gordonmu" % "gordonmu-coio" % "0.8.0"
[io.github.gordonmu/gordonmu-coio "0.8.0"]

Dependencies

runtime (5)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.20
org.jetbrains.kotlinx : kotlinx-coroutines-core-jvm jar 1.4.2
org.jetbrains.kotlinx : kotlinx-coroutines-jdk8 jar 1.4.2
io.github.microutils : kotlin-logging jar 1.8.3
org.slf4j : slf4j-api jar 1.7.30

test (7)

Group / Artifact Type Version
org.assertj : assertj-core jar 3.17.2
org.junit.jupiter : junit-jupiter-api jar 5.6.2
io.mockk : mockk jar 1.10.0
org.awaitility : awaitility jar 4.0.3
org.awaitility : awaitility-kotlin jar 4.0.3
org.junit.jupiter : junit-jupiter-engine jar 5.6.2
org.apache.logging.log4j : log4j-slf4j-impl jar 2.13.3

Project Modules

There are no modules declared in this project.

Java CI Download

CoIO

Kotlin Coroutines make asynchronous programming simple and efficient but there is no official library that provides IO operations in a coroutine. These operations, such as reading a file or sending data over a TCP connection, benefit heavily from coroutines because they can take relatively long and use few CPU resources. This library seeks to wrap existing Java non-blocking IO libraries to provide a uniform and simple API with coroutines.

Features

  • Simple, lean stream interfaces with suspend read and write functions using ByteBuffers
  • Supports file access
  • Supports TCP servers and clients
  • Supports UDP unicast and multicast
  • Wrapping any stream with TLS

Alternatives

  • Official Kotlin coroutine IO - Does not exist yet.
  • Java blocking IO - Must be used with care in coroutines because the blocking operations can consume your worker threads. Consider using the IO Dispatcher.
  • Java NIO - Efficient non-blocking operation available but steep learning curve and quite a bit of code needed to build coroutines.
  • Java NIO2 - Nice asynchronous methods that can be easily wrapped into a coroutine.

Usage

TCP Server

val server = CoIOTcp.listen(8775)

for (connection in server) {
    launch {
        val buf = ByteBuffer.allocate(1024)
        connection.readFully(buf)
        buf.flip()
        connection.writeFully(buf)
    }
}

Versions

Version
0.8.0