scoop:scoop.asyncio:0.1.0
src/loop/completion.scoop
Selected production source · src/loop/completion.scoop
1
package scoop.asyncio3
import scoop.platform.system.*5
internal struct NativeEvent(val id: Long, val result: IoResult)7
internal enum IoStart {8
Pending, Finished(NativeEvent)9
}11
internal fun nativeStatus(id: Long, status: Int): IoStart = if (status < 0)12
IoStart.Finished(NativeEvent(id, IoResult.Failed(nativeStatusError(status), 0L)))13
else14
IoStart.Pending16
internal fun nativeStatus(id: Long, status: NativeIoStatus): IoStart = if (status.code != 0)17
IoStart.Finished(NativeEvent(id, IoResult.Failed(nativeStatusError(status), 0L)))18
else19
IoStart.Pending21
internal fun resultFailure(22
operation: String,23
result: IoResult,24
context: OsString? = None25
): Throwable? = when (result) {26
case Failed(val error, _) ->27
Some(28
PlatformException(operation, error.kind, Some(error), context)29
)30
case _ -> None31
}33
internal fun completionFailure(34
operation: String,35
result: IoResult,36
selected: Throwable?,37
context: OsString? = None38
): Throwable? = when (selected) {39
case Some(_) -> selected;40
case None -> resultFailure(operation, result, context)41
}