Skip to content

Instantly share code, notes, and snippets.

View FRosner's full-sized avatar

Frank Rosner FRosner

View GitHub Profile
1 /sbin/init
+-- 196 /usr/sbin/syslogd -s
+-- 354 /usr/sbin/cron -s
+-- 391 login
+-- 400 bash
+-- 701 /usr/local/bin/pstree
FROM openjdk:8u212-jdk-slim
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Python3=3.5.3-1 \
Python3-pip=9.0.1-2+deb9u1 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements.txt
RUN pip3 install --upgrade -r requirements.txt
suspend fun <T> awaitEvent(block: (h: Handler<T>) -> Unit): T {
return suspendCancellableCoroutine { cont: CancellableContinuation<T> ->
try {
block.invoke(Handler { t ->
cont.resume(t)
})
} catch (e: Exception) {
cont.resumeWithException(e)
}
}
suspend fun HttpServer.listenAwait(port: Int, host: String): HttpServer
fun listen(port: Int, host: String, listenHandler: Handler<AsyncResult<HttpServer>>): HttpServer
suspend fun placeOrder(userData: UserData, orderData: OrderData): Order {
val user = createUser(userData) // asynchronous call to user service
val order = createOrder(user, orderData) // asynchronous call to order service
return order
}
suspend fun createUser(userData: UserData): User { ... }
suspend fun createOrder(user: User, orderData: OrderData): Order { ... }
fun placeOrder(userData: UserData, orderData: OrderData): Order {
val user = createUser(userData) // synchronous call to user service
val order = createOrder(user, orderData) // synchronous call to order service
return order
}
fun createUser(userData: UserData): User { ... }
fun createOrder(user: User, orderData: OrderData): Order { ... }
import kotlinx.coroutines.*
fun main() {
GlobalScope.launch { // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
}
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
}
val server = vertx.createHttpServer().listenAwait()
val response = WebClient.create(vertx)
.get(server.actualPort(), "localhost", "").sendAwait()
println(response.bodyAsString())
vertx.createHttpServer().listen {
if (it.succeeded()) {
val server = it.result()
WebClient.create(vertx).get(server.actualPort(), "localhost", "").send {
if (it.succeeded()) {
val response = it.result()
println(response.bodyAsString())
}
}
}