Created
November 6, 2025 15:42
-
-
Save ileasile/f2529277011b0f43243809e2396debd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells" : [ { | |
| "cell_type" : "code", | |
| "metadata" : { | |
| "collapsed" : true, | |
| "ExecuteTime" : { | |
| "end_time" : "2025-11-06T14:33:58.677970Z", | |
| "start_time" : "2025-11-06T14:33:55.619835Z" | |
| }, | |
| "executionRelatedData" : { | |
| "compiledClasses" : [ "Line_3_jupyter" ] | |
| } | |
| }, | |
| "source" : "%use coroutines", | |
| "id" : "457882cc053a4565", | |
| "outputs" : [ ], | |
| "execution_count" : 1 | |
| }, { | |
| "metadata" : { | |
| "executionRelatedData" : { | |
| "compiledClasses" : [ "Line_7_jupyter", "Line_10_jupyter", "Line_8_jupyter", "Line_6_jupyter", "Line_4_jupyter", "Line_9_jupyter", "Line_11_jupyter" ] | |
| }, | |
| "ExecuteTime" : { | |
| "end_time" : "2025-11-06T15:38:05.446407Z", | |
| "start_time" : "2025-11-06T15:37:50.325734Z" | |
| } | |
| }, | |
| "cell_type" : "code", | |
| "source" : [ "import kotlin.time.TimeSource\n", "\n", "val scope = CoroutineScope(Dispatchers.Default)\n", "\n", "val mark = TimeSource.Monotonic.markNow()\n", "\n", "runBlocking {\n", " try {\n", " supervisorScope {\n", " println(\"Started ${mark.elapsedNow()}\")\n", " withTimeout(5000L) {\n", " println(\"Running ${mark.elapsedNow()}\")\n", " val result = scope.async {\n", " Thread.sleep(10000L)\n", " println(\"Finished async ${mark.elapsedNow()}\")\n", " }\n", " result.await()\n", " println(\"Finished ${mark.elapsedNow()}\")\n", " }\n", " }\n", " } catch (e: Throwable) {\n", " println(\"TIMEOUT: $e\")\n", " }\n", "\n", " delay(10000L)\n", " println(\"Done ${mark.elapsedNow()}\")\n", "}" ], | |
| "id" : "78b2fbc5f7a3d794", | |
| "outputs" : [ { | |
| "name" : "stdout", | |
| "output_type" : "stream", | |
| "text" : [ "Started 433.625us\n", "Running 827.458us\n", "TIMEOUT: kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 5000 ms\n", "Finished async 10.006207208s\n", "Done 15.010331833s\n" ] | |
| } ], | |
| "execution_count" : 9 | |
| }, { | |
| "metadata" : { }, | |
| "cell_type" : "code", | |
| "outputs" : [ ], | |
| "execution_count" : null, | |
| "source" : "", | |
| "id" : "8269f1ec8e0e7c66" | |
| } ], | |
| "metadata" : { | |
| "kernelspec" : { | |
| "display_name" : "Kotlin", | |
| "language" : "kotlin", | |
| "name" : "kotlin" | |
| }, | |
| "language_info" : { | |
| "name" : "kotlin", | |
| "version" : "2.2.20", | |
| "mimetype" : "text/x-kotlin", | |
| "file_extension" : ".kt", | |
| "pygments_lexer" : "kotlin", | |
| "codemirror_mode" : "text/x-kotlin", | |
| "nbconvert_exporter" : "" | |
| } | |
| }, | |
| "nbformat" : 4, | |
| "nbformat_minor" : 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment