kotlinx-coroutines-core / kotlinx.coroutines.experimental / Job
interface Job : Element
(source)
A background job. A job can be cancelled at any time with cancel function that forces it to become completed immediately.
It has two states:
import java.util.BitSet; | |
/** | |
* @author Roman Elizarov | |
*/ | |
public class Regex { | |
private final int n; // number of actual chars in pattern (w/o *) | |
private final char[] cs; // actual chars in pattens (w/o *) | |
private final boolean[] rs; // true when * applies | |
private final int[] fs; // transitive closure of match, given that an empty string matches x* |
/* | |
* QDS - Quick Data Signalling Library | |
* Copyright (C) 2002-2015 Devexperts LLC | |
* | |
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. | |
* If a copy of the MPL was not distributed with this file, You can obtain one at | |
* http://mozilla.org/MPL/2.0/. | |
*/ | |
package com.devexperts.util; |
import java.io.InputStream | |
import java.nio.ByteBuffer | |
import java.nio.channels.AsynchronousFileChannel | |
import java.nio.channels.CompletionHandler | |
import java.nio.file.Path | |
import java.nio.file.Paths | |
import java.nio.file.StandardOpenOption.CREATE | |
import java.nio.file.StandardOpenOption.WRITE | |
import java.time.Instant | |
import java.util.concurrent.CompletableFuture |
import java.util.concurrent.CompletableFuture | |
// ====================================================================================================== | |
// demo the problem with naive await implementation | |
fun main(args: Array<String>) { | |
val n: Int = 100000 | |
var actualCount = 0; | |
async<Unit> { | |
repeat(n) { // repeat n times |
// UPDATE: Everyone finding this gist via Google! | |
// Modern kotlinx.coroutines has out-of-the-box support for asyncLazy with the following expression: | |
// val myLazyValue = async(start = CoroutineStart.LAZY) { ... } | |
// Use myLazyValue.await() when you need it | |
// ---------------- public api ---------------- | |
public interface AsyncLazy<out T> { | |
public suspend fun value(): T | |
public fun isInitialized(): Boolean |
kotlinx-coroutines-core / kotlinx.coroutines.experimental / Job
interface Job : Element
(source)
A background job. A job can be cancelled at any time with cancel function that forces it to become completed immediately.
It has two states:
kotlinx-coroutines-core / kotlinx.coroutines.experimental / Job
interface Job : Element
(source)
A background job. A job can be cancelled at any time with cancel function that forces it to become completed immediately.
It has two states:
import javafx.beans.property.SimpleStringProperty | |
import javafx.geometry.Insets | |
import javafx.scene.Scene | |
import javafx.scene.control.ButtonBar | |
import javafx.scene.control.ButtonType | |
import javafx.scene.control.Dialog | |
import javafx.util.Callback | |
import kotlinx.coroutines.experimental.CommonPool | |
import kotlinx.coroutines.experimental.javafx.JavaFx | |
import kotlinx.coroutines.experimental.launch |
public class CancellableHandlerContext( | |
private val handler: Handler | |
) : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor, Delay | |
{ | |
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = | |
DispatchedContinuation(continuation) | |
override fun scheduleResumeAfterDelay(time: Long, unit: TimeUnit, continuation: CancellableContinuation<Unit>) { | |
handler.postDelayed(object : ResumeTask<Unit>(continuation) { | |
override fun resume() = continuation.resume(Unit) |
import kotlin.coroutines.experimental.* | |
import kotlin.coroutines.experimental.intrinsics.* | |
fun main(args: Array<String>) { | |
enumerate { | |
if (flip("A")) { | |
if (flip("B")) 1 else 2 | |
} else { | |
if (flip("C")) 3 else if (flip("D")) 4 else 5 | |
} |