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:
| /* | |
| * 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.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* |
| 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 |
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) |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| val application = this | |
| launch(UI) { // start a new coroutine in Android UI context | |
| // switch to background thread for some long-running initialization | |
| run(CommonPool) { AndroidThreeTen.init(application) } | |
| // then init UI | |
| initUI() | |
| } |
| /* | |
| fun BluetoothSocket.asyncListen(): Flowable<String> = | |
| flowable<String>(BackpressureStrategy.BUFFER) { emitter -> | |
| try { | |
| val reader = BufferedReader(InputStreamReader(inputStream)) | |
| while (!emitter.isCancelled) { | |
| reader.readLine()?.let { emitter.onNext(it) } | |
| } | |
| } catch (e: IOException) { | |
| emitter.onError(e) |