Scoop API

scoop:scoop.asyncio:0.1.0

src/event_loop.scoop

Selected production source · src/event_loop.scoop

1package scoop.asyncio
3import scoop.time.Duration
4import scoop.platform.net.*
5import scoop.platform.system.OsString
6import scoop.platform.fs.*
7import scoop.platform.process.Command
9/**
10 * The suspending filesystem, timer, resolver, TCP, UDP, and TTY service installed for a structured
11 * coroutine scope. Resources and operations belong to their creating loop.
12 */
13public interface EventLoop {
14 /**
15 * Runs a single-use native payload on a worker and waits for completion before releasing its
16 * active borrow.
17 */
18 /** The active owner executor. Access before startup or after its termination is rejected. */
19 public val executor: CoroutineExecutor
20 /**
21 * Suspends for a nonnegative duration and follows current-job cancellation.
22 */
23 public suspend fun sleep(duration: Duration)
24 /**
25 * Schedules one owner-thread notification without creating a coroutine. None means elapsed;
26 * an error reports timer failure. Disposal or current-job cancellation suppresses an unselected
27 * notification. The callback does not inherit Context and must not block the owner.
28 */
29 public fun schedule(duration: Duration, completion: (Throwable?) -> Unit): Disposable
30 /**
31 * Resolves the host and port, optionally restricted to one address family.
32 */
33 public suspend fun resolve(host: OsString, port: Int, family: AddressFamily? = None): Array<
34 SocketAddress
35 >
36 /**
37 * Opens an owned asynchronous file using explicit access, creation, and truncation options.
38 */
39 public suspend fun openFile(path: Path, options: OpenOptions = OpenOptions()): AsyncFile
40 /**
41 * Opens an owned asynchronous terminal handle.
42 */
43 public suspend fun openTty(): AsyncTty
44 /** Launches a child on an owned pseudoterminal using cell dimensions. */
45 public suspend fun spawnPty(
46 command: Command,
47 columns: Long,
48 rows: Long,
49 searchPath: Boolean = false
50 ): AsyncPty
51 /**
52 * Queries filesystem metadata, optionally following symbolic links.
53 */
54 public suspend fun metadata(path: Path, followLinks: Boolean = true): FileMetadata
55 /**
56 * Moves a filesystem entry, replacing the destination only when requested.
57 */
58 public suspend fun moveFile(source: Path, destination: Path, replaceExisting: Boolean = false)
59 /**
60 * Deletes the selected filesystem entry.
61 */
62 public suspend fun deleteFile(path: Path)
63 /**
64 * Creates missing parent directories with the requested mode, subject to the process umask.
65 */
66 public suspend fun createDirectories(path: Path, mode: Int = 0x1ff)
67 /**
68 * Creates a unique temporary file and returns both its path and open handle.
69 */
70 public suspend fun createTempFile(
71 parent: Path? = None,
72 prefix: String = "scoop-"
73 ): TemporaryFile
74 /**
75 * Opens an owned directory enumeration cursor.
76 */
77 public suspend fun openDirectory(path: Path): AsyncDirectoryEntries
78 /**
79 * Binds an owned UDP socket, optionally enabling address reuse.
80 */
81 public suspend fun bindUdp(
82 address: SocketAddress,
83 reuseAddress: Boolean = false
84 ): AsyncUdpSocket
85 /**
86 * Connects to an IP endpoint, or resolves and races candidates using the supplied host
87 * connection options. The returned stream has independent ownership.
88 */
89 public suspend fun connectTcp(address: SocketAddress): AsyncTcpStream
90 /**
91 * Connects to an IP endpoint, or resolves and races candidates using the supplied host
92 * connection options. The returned stream has independent ownership.
93 */
94 public suspend fun connectTcp(
95 host: OsString,
96 port: Int,
97 options: TcpConnectOptions = tcpConnectOptions()
98 ): AsyncTcpStream
99 /**
100 * Binds and listens for TCP connections with the requested backlog and address-reuse setting.
101 */
102 public suspend fun listenTcp(
103 address: SocketAddress,
104 backlog: Int = 128,
105 reuseAddress: Boolean = false
106 ): AsyncTcpListener