os

sleep

fun sleep(float ms) > void 

Wait for the given amount of milliseconds

  • ms: amount of milliseconds to wait

time

fun time() > float 

Returns: epoch time in ms

env

fun env(str key) > str?

Returns environment variable under key

  • key: environment variable name

tmpDir

fun tmpDir() > str 

Returns: path to system temp directory

tmpFilename

fun tmpFilename(str? prefix) > str 
  • prefix: prefix to the temp file name

Returns: a temporary file name in system tmp dir

exit

fun exit(int exitCode) > void 

Exit program with exitCode

  • exitCode: exit code

execute

fun execute([str] command) > int !> FileSystemError, UnexpectedError 

Execute command and return its exit code

  • command: command to execute

Returns: exit code of the command

SocketProtocol

enum SocketProtocol {
    tcp,
    udp,
    ipc,
}

Protocols supported over a socket

Socket

object Socket 

A socket

connect

static fun connect(str address, int port = 0, SocketProtocol netProtocol) > Socket !> InvalidArgumentError, SocketError, NotYetImplementedError

Opens a socket

  • address: A string containing either a IPv4, IPv6 or path to a socket file (IPC)
  • port: Port to which to connect
  • protocol: Protocol to use

Returns: A new Socket opened and ready to use

close

fun close() > void

Close the socket

receive

fun receive(int n) > str? !> InvalidArgumentError, FileSystemError, ReadWriteError, UnexpectedError

Receive at most n bytes from the socket

  • n: How many bytes we're prepare to receive

Returns: The bytes received or null if nothing to read

receiveLine

fun receiveLine(int? maxSize) > str? !> FileSystemError, UnexpectedError, ReadWriteError

Receive from socket until it's closed or a linefeed is received

Returns: The bytes received or null if nothing to read

receiveAll

fun receiveAll(int? maxSize) > str? !> FileSystemError, UnexpectedError, ReadWriteError

Receive from socket until it's closed

Returns: The bytes received or null if nothing to read

send

fun send(str bytes) > void !> FileSystemError, ReadWriteError, UnexpectedError

Send bytes on the socket

  • bytes: Bytes to send

TcpServer

object TcpServer 

A TCP Server

init

static fun init(str address, int port, bool reuseAddr, bool reusePort) > TcpServer !> SocketError, UnexpectedError, InvalidArgumentError, FileSystemError

Starts a TCP server

  • address: Address to listen on
  • port: Port to listen on
  • reuseAddr: Wether we want to accept multiple connections
  • reusePort: Wether we want to accept multiple connections

Returns: New TcpServer bound to <address>:<port>

accept

fun accept() > Socket !> SocketError, UnexpectedError

Accept a new connection

Returns: Socket opened with the client

close

fun close() > void

Close server

Last Updated:
Contributors: hshq, Benoit Giannangeli