Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/async.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async fn[X] Task::wait(Self[X]) -> X raise
type TaskGroup[X]
fn[X] TaskGroup::add_defer(Self[X], async () -> Unit raise) -> Unit raise
fn[X] TaskGroup::return_immediately(Self[X], X) -> Unit raise
fn[G, X] TaskGroup::spawn(Self[G], async () -> X raise, no_wait~ : Bool = .., allow_failure~ : Bool = ..) -> Task[X] raise
fn[X] TaskGroup::spawn_bg(Self[X], async () -> Unit raise, no_wait~ : Bool = .., allow_failure~ : Bool = ..) -> Unit raise
fn[X] TaskGroup::spawn_loop(Self[X], async () -> IterResult raise, no_wait~ : Bool = .., allow_failure~ : Bool = .., retry~ : RetryMethod = ..) -> Unit raise
fn[G, X] TaskGroup::spawn(Self[G], async () -> X raise, no_wait? : Bool, allow_failure? : Bool) -> Task[X] raise
fn[X] TaskGroup::spawn_bg(Self[X], async () -> Unit raise, no_wait? : Bool, allow_failure? : Bool) -> Unit raise
fn[X] TaskGroup::spawn_loop(Self[X], async () -> IterResult raise, no_wait? : Bool, allow_failure? : Bool, retry? : RetryMethod) -> Unit raise

// Type aliases
pub typealias @moonbitlang/async/aqueue.Queue as Queue
Expand Down
2 changes: 1 addition & 1 deletion src/example/tcp_ping_pong/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ suberror ServerTerminate derive(Show)
let port = 4201

///|
pub(all) type Printer (String) -> Unit
pub(all) struct Printer((String) -> Unit)

///|
async fn server(println : Printer) -> Unit raise {
Expand Down
2 changes: 1 addition & 1 deletion src/example/tcp_ping_pong/tcp_ping_pong.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ServerTerminate
impl Show for ServerTerminate

// Types and methods
pub(all) type Printer (String) -> Unit
pub(all) struct Printer((String) -> Unit)
fn Printer::inner(Self) -> (String) -> Unit

// Type aliases
Expand Down
2 changes: 1 addition & 1 deletion src/example/udp_ping_pong/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ suberror ServerTerminate derive(Show)
let port = 4201

///|
pub(all) type Printer (String) -> Unit
pub(all) struct Printer((String) -> Unit)

///|
async fn server(println : Printer) -> Unit raise {
Expand Down
2 changes: 1 addition & 1 deletion src/example/udp_ping_pong/udp_ping_pong.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ServerTerminate
impl Show for ServerTerminate

// Types and methods
pub(all) type Printer (String) -> Unit
pub(all) struct Printer((String) -> Unit)
fn Printer::inner(Self) -> (String) -> Unit

// Type aliases
Expand Down
8 changes: 3 additions & 5 deletions src/fs/fs.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

///|
type File Int
struct File(Int)

///|
pub fn File::close(self : File) -> Unit {
Expand Down Expand Up @@ -127,10 +127,9 @@ pub async fn File::read(
self : File,
buf : FixedArray[Byte],
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Int raise {
let File(fd) = self
let len = len.unwrap_or(buf.length() - offset)
let job = @thread_pool.read_job(fd, buf, offset, len)
@event_loop.perform_job(job)
}
Expand All @@ -146,10 +145,9 @@ pub async fn File::write(
self : File,
buf : Bytes,
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Unit raise {
let File(fd) = self
let len = len.unwrap_or(buf.length())
let job = @thread_pool.write_job(fd, buf, offset, len)
ignore(@event_loop.perform_job(job))
}
Expand Down
10 changes: 5 additions & 5 deletions src/fs/fs.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
package "moonbitlang/async/fs"

// Values
async fn create(Bytes, permission~ : Int, sync~ : SyncMode = ..) -> File raise
async fn create(Bytes, permission~ : Int, sync? : SyncMode) -> File raise

async fn open(Bytes, mode~ : Mode, sync~ : SyncMode = .., append~ : Bool = .., create? : Int, truncate~ : Bool = ..) -> File raise
async fn open(Bytes, mode~ : Mode, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> File raise

fn opendir(Bytes) -> Directory raise

Expand All @@ -15,17 +15,17 @@ async fn remove(Bytes) -> Unit raise
// Types and methods
type Directory
fn Directory::close(Self) -> Unit
async fn Directory::read_all(Self, include_hidden~ : Bool = .., include_special~ : Bool = ..) -> Array[Bytes] raise
async fn Directory::read_all(Self, include_hidden? : Bool, include_special? : Bool) -> Array[Bytes] raise

type File
fn File::as_dir(Self) -> Directory raise
fn File::close(Self) -> Unit
fn File::curr_pos(Self) -> Int64 raise
fn File::kind(Self) -> FileKind raise
async fn File::read(Self, FixedArray[Byte], offset~ : Int = .., len? : Int) -> Int raise
async fn File::read(Self, FixedArray[Byte], offset? : Int, len? : Int) -> Int raise
fn File::seek(Self, Int64, mode~ : SeekMode) -> Int64 raise
fn File::size(Self) -> Int64 raise
async fn File::write(Self, Bytes, offset~ : Int = .., len? : Int) -> Unit raise
async fn File::write(Self, Bytes, offset? : Int, len? : Int) -> Unit raise

pub(all) enum FileKind {
Unknown
Expand Down
2 changes: 1 addition & 1 deletion src/internal/event_loop/poll.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

///|
priv type Instance Int
priv struct Instance(Int)

///|
const NoEvent = 0
Expand Down
10 changes: 4 additions & 6 deletions src/pipe/pipe.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

///|
/// The read end of a pipe
type PipeRead Int
struct PipeRead(Int)

///|
pub fn PipeRead::fd(self : PipeRead) -> Int {
Expand All @@ -24,7 +24,7 @@ pub fn PipeRead::fd(self : PipeRead) -> Int {

///|
/// The write end of a pipe
type PipeWrite Int
struct PipeWrite(Int)

///|
pub fn PipeWrite::fd(self : PipeWrite) -> Int {
Expand Down Expand Up @@ -127,9 +127,8 @@ pub async fn PipeRead::read(
self : PipeRead,
buf : FixedArray[Byte],
offset~ : Int = 0,
max_len? : Int,
max_len~ : Int = buf.length() - offset,
) -> Int raise {
let max_len = max_len.unwrap_or(buf.length() - offset)
let PipeRead(fd) = self
@event_loop.prepare_fd_read(fd)
let n_read = read_ffi(fd, buf, offset, max_len)
Expand Down Expand Up @@ -180,9 +179,8 @@ pub async fn PipeWrite::write(
self : PipeWrite,
buf : Bytes,
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Unit raise {
let len = len.unwrap_or(buf.length() - offset)
let PipeWrite(fd) = self
@event_loop.prepare_fd_write(fd)
for sent = 0; sent < len; {
Expand Down
4 changes: 2 additions & 2 deletions src/pipe/pipe.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ impl Show for PipeClosed
type PipeRead
fn PipeRead::close(Self) -> Unit
fn PipeRead::fd(Self) -> Int
async fn PipeRead::read(Self, FixedArray[Byte], offset~ : Int = .., max_len? : Int) -> Int raise
async fn PipeRead::read(Self, FixedArray[Byte], offset? : Int, max_len? : Int) -> Int raise
async fn PipeRead::read_exactly(Self, Int) -> Bytes raise

type PipeWrite
fn PipeWrite::close(Self) -> Unit
fn PipeWrite::fd(Self) -> Int
async fn PipeWrite::write(Self, Bytes, offset~ : Int = .., len? : Int) -> Unit raise
async fn PipeWrite::write(Self, Bytes, offset? : Int, len? : Int) -> Unit raise

// Type aliases

Expand Down
2 changes: 1 addition & 1 deletion src/process/process.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import(
)

// Values
async fn spawn(Bytes, Array[Bytes], extra_env~ : Map[Bytes, Bytes] = .., inherit_env~ : Bool = .., stdin? : @pipe.PipeRead, stdout? : @pipe.PipeWrite, stderr? : @pipe.PipeWrite) -> Process raise
async fn spawn(Bytes, Array[Bytes], extra_env? : Map[Bytes, Bytes], inherit_env? : Bool, stdin? : @pipe.PipeRead, stdout? : @pipe.PipeWrite, stderr? : @pipe.PipeWrite) -> Process raise

// Errors

Expand Down
2 changes: 1 addition & 1 deletion src/socket/addr.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

///|
/// IPv4 address + port number
type Addr Bytes derive(Eq, Compare, Hash)
struct Addr(Bytes) derive(Eq, Compare, Hash)

///|
pub extern "C" fn Addr::new(ip : UInt, port : Int) -> Addr = "moonbitlang_async_make_ip_addr"
Expand Down
14 changes: 7 additions & 7 deletions src/socket/socket.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ async fn TCP::accept(Self) -> (Self, Addr) raise
fn TCP::bind(Self, Addr) -> Unit raise
fn TCP::close(Self) -> Unit
async fn TCP::connect(Self, Addr) -> Unit raise
fn TCP::enable_keepalive(Self, idle_before_keep_alive~ : Int = .., keep_alive_count~ : Int = .., keep_alive_interval~ : Int = ..) -> Unit raise
fn TCP::enable_keepalive(Self, idle_before_keep_alive? : Int, keep_alive_count? : Int, keep_alive_interval? : Int) -> Unit raise
fn TCP::listen(Self) -> Unit raise
fn TCP::new() -> Self raise
async fn TCP::recv(Self, FixedArray[Byte], offset~ : Int = .., max_len? : Int) -> Int raise
async fn TCP::recv(Self, FixedArray[Byte], offset? : Int, max_len? : Int) -> Int raise
async fn TCP::recv_exactly(Self, Int) -> Bytes raise
async fn TCP::send(Self, Bytes, offset~ : Int = .., len? : Int) -> Unit raise
async fn TCP::send(Self, Bytes, offset? : Int, len? : Int) -> Unit raise

type UDP
fn UDP::bind(Self, Addr) -> Unit raise
fn UDP::close(Self) -> Unit
fn UDP::connect(Self, Addr) -> Unit raise
fn UDP::new() -> Self raise
async fn UDP::recv(Self, FixedArray[Byte], offset~ : Int = .., max_len? : Int) -> Int raise
async fn UDP::recvfrom(Self, FixedArray[Byte], offset~ : Int = .., max_len? : Int) -> (Int, Addr) raise
async fn UDP::send(Self, Bytes, offset~ : Int = .., len? : Int) -> Unit raise
async fn UDP::sendto(Self, Bytes, Addr, offset~ : Int = .., len? : Int) -> Unit raise
async fn UDP::recv(Self, FixedArray[Byte], offset? : Int, max_len? : Int) -> Int raise
async fn UDP::recvfrom(Self, FixedArray[Byte], offset? : Int, max_len? : Int) -> (Int, Addr) raise
async fn UDP::send(Self, Bytes, offset? : Int, len? : Int) -> Unit raise
async fn UDP::sendto(Self, Bytes, Addr, offset? : Int, len? : Int) -> Unit raise

// Type aliases

Expand Down
8 changes: 3 additions & 5 deletions src/socket/tcp.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

///|
/// A TCP socket directly corresponding to OS socket.
type TCP Int
struct TCP(Int)

///|
/// Create a new TCP socket using the `socket(2)` system call.
Expand Down Expand Up @@ -128,9 +128,8 @@ pub async fn TCP::recv(
self : TCP,
buf : FixedArray[Byte],
offset~ : Int = 0,
max_len? : Int,
max_len~ : Int = buf.length() - offset,
) -> Int raise {
let max_len = max_len.unwrap_or(buf.length() - offset)
let TCP(sock) = self
@event_loop.prepare_fd_read(sock)
let n_read = recv_ffi(sock, buf, offset, max_len)
Expand Down Expand Up @@ -181,9 +180,8 @@ pub async fn TCP::send(
self : TCP,
buf : Bytes,
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Unit raise {
let len = len.unwrap_or(buf.length() - offset)
let TCP(sock) = self
@event_loop.prepare_fd_write(sock)
for sent = 0; sent < len; {
Expand Down
14 changes: 5 additions & 9 deletions src/socket/udp.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

///|
/// A UDP socket directly corresponding to OS socket
type UDP Int
struct UDP(Int)

///|
/// Create a new UDP socket using the `socket(2)` system call.
Expand Down Expand Up @@ -73,9 +73,8 @@ pub async fn UDP::recv(
self : UDP,
buf : FixedArray[Byte],
offset~ : Int = 0,
max_len? : Int,
max_len~ : Int = buf.length() - offset,
) -> Int raise {
let max_len = max_len.unwrap_or(buf.length() - offset)
let UDP(sock) = self
@event_loop.prepare_fd_read(sock)
let n_read = recv_ffi(sock, buf, offset, max_len)
Expand Down Expand Up @@ -110,9 +109,8 @@ pub async fn UDP::recvfrom(
self : UDP,
buf : FixedArray[Byte],
offset~ : Int = 0,
max_len? : Int,
max_len~ : Int = buf.length() - offset,
) -> (Int, Addr) raise {
let max_len = max_len.unwrap_or(buf.length() - offset)
let UDP(sock) = self
@event_loop.prepare_fd_read(sock)
let addr = Addr::new(0, 0)
Expand Down Expand Up @@ -142,9 +140,8 @@ pub async fn UDP::send(
self : UDP,
buf : Bytes,
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Unit raise {
let len = len.unwrap_or(buf.length() - offset)
let UDP(sock) = self
@event_loop.prepare_fd_write(sock)
for {
Expand Down Expand Up @@ -175,9 +172,8 @@ pub async fn UDP::sendto(
buf : Bytes,
addr : Addr,
offset~ : Int = 0,
len? : Int,
len~ : Int = buf.length() - offset,
) -> Unit raise {
let len = len.unwrap_or(buf.length() - offset)
let UDP(sock) = self
@event_loop.prepare_fd_write(sock)
for {
Expand Down
Loading