Scoop API

scoop:scoop.window:0.1.0

src/native/application_host.scoop

Selected production source · src/native/application_host.scoop

1package scoop.window.native
3import scoop.window.*
5/** Business delivery owned by the existing asyncio session. */
6public interface ApplicationAttachment {
7 public fun post(block: () -> Unit): Boolean
8 public fun requestClose()
9}
11/** Native application operations used by the separate asyncio integration Cone. */
12public class ApplicationHost internal constructor(internal val owner: ApplicationOwner) {
13 public fun isCurrentThread(): Boolean = owner.isCurrentThread()
14 /** Borrows a readable descriptor without consuming, resetting, or closing it. */
15 @Unsafe
16 public fun watchReadable(descriptor: Int, ready: () -> Unit): ApplicationWatch =
17 installReadableWatch(owner, descriptor, ready)
18 /** Borrows a Windows manual-reset event without resetting or closing it. */
19 @Unsafe
20 public fun watchWindowsEvent(event: Ptr<Unit>, ready: () -> Unit): ApplicationWatch =
21 installWindowsWatch(owner, event, ready)
22 public fun postControl(block: () -> Unit): Boolean = owner.mailbox.postControl(block)
23 /** Reports session completion exactly once; its watches must already be retired. */
24 public fun complete(failure: Throwable?) {
25 owner.complete(failure)
26 }
27 /** Starts shutdown from an owner control callback, including root cancellation. */
28 public fun requestExit() {
29 owner.checkThread();
30 owner.beginExit()
31 }
34/** Runs with an attachment installed before the first business event can be served. */
35@Unsafe
36public fun Application.runAttached(
37 handler: ApplicationHandler,
38 attach: (ApplicationHost) -> ApplicationAttachment
39) {
40 owner.run(handler, Some(attach))