Releases: moonbitlang/async
v0.15.0
-
[breaking] Support closing
@async.Queuevia.close(). Detailed behavior:- any blocked
putorgetoperation will fail immediately after calling.close() - calling
putortry_puton a closed queue will fail immediately - calling
getortry_geton a closed queue can still retrieve buffered elements in the queue. If the queue is closed and empty,getandtry_getwill fail immediately..close(clear=true)(clear=falseby default) result in a hard close. Buffered elements in the queue will be discarded, and subsequentget&try_getoperations always fail immediately
By default, the error
@aqueue.QueueAlreadyClosedwill be raised for the above scenarios. However, the error can be customized via the error optional argument of.close().This change is breaking because
try_getandtry_putmay now raise error. - any blocked
-
add
@async.lazy_initfor creating lazily initialized async values. The result of lazily initialized async values can be retrieved by.wait(). The async initialization process will start automatically on the first.wait()request, and the result, once computed, will be cached. If all waiters are cancelled before the initialization completes, the initialization process will be cancelled automatically. -
bug fix:
@async.now()did not work in JavaScript backend previously -
adapt to latest MoonBit release (v0.6.35)
v0.14.3
- add
.ping()method to@websocket.Connfor actively sending PING message and wait for corresponding PONG reply - remove some deprecated API:
@fs.File::{seek,curr_pos},@pipe.{stdin,stdout,stderr} - fix bug concerning behavior of current task calling
@async.TaskGroup::return_immediately
v0.14.2
- add WebSocket support via
moonbitlang/async/websocket - fix API name typo:
@http.{Client.ServerConnection}.entre_passthrough_mode => enter_passthrough_mode - all
.close()methods are idempotent: things can be closed multiple times, only the first.close()takes effect - HTTP: no longer use chunked encoding when the body is empty. This improves compatibility with some restrictive client/server
- adapt to MoonBit v0.6.33
v0.14.1
v0.14.0
-
[breaking] allow different behaviors for
@async.Queue::put. On queue creation, akindargument can be provided, with four options:Unbounded: this is the previous behavior. The queue has unbounded size, andputnever block or fail. Ifkindis omitted in@async.Queue::new, this is also the default behavior, for compatibility sake. But a warning will be reported ifkindis omitted.Blocking(n): the queue's size must not exceedn. If the queue is full,putwill block until the queue has enough space. Multiple blocked writers are processed in a FIFO mannerDiscardOldest(n): the queue's size must not exceedn. If the queue is full,putwill discard the oldest element.putnever block or fail for this kind of queueDiscardLatest(n): the queue's size must not exceedn. If the queue is full,putwill discard the newest element (i.e. the argument ofput).putnever block or fail for this kind of queue
this change is breaking because
putis nowasync. Note that for all kinds of queues exceptBlocking,putnever actually suspend. A new APItry_putis also introduced, which can be used in non-async context.try_putwill returntrueiff the queue is not full and the new element is added. Note thattry_putwill not discard elements forDiscardOldestorDiscardLatestqueues. -
Refined API for HTTP server. A new type,
@http.Serveris introduced, with various APIs. The previous@http.run_serveris deprecated in favor of@http.Server::new(..).run_forever(..). Compared to@http.run_server:- separating server creation and running allows binding the server to a random port for testing
- the callback of
@http.Server::run_foreverhandles a single request instead of connection. It accepts three parameters: the request header, a&@io.Readerfor request body, and a@http.ServerConnectionfor writing response. This way the API is cleaner, and the user no longer need to manually loop for requests over the connection.
-
various HTTP client related API now accepts an extra
proxy? : @http.Clientparameter. If present,proxyshould be another HTTP client in a clean state (i.e. no in the middle of a request). ACONNECTrequest will be sent to the proxy client to establish a opaque tunnel, and subsequent traffic will go through this tunnel -
the
portargument of@http.getetc., in favor of specifying the port in the URI, in the standard way.@http.Client::connectis deprecated in favor of a new API@http.Client::new. Except name difference,@http.Client::newno longer accept theprotocolandportparameter, and instead require them to be specified in the URI -
add
@async.is_cancellation_errorto detect if an error is the internal error used to represent cancellation. Note that@async.is_cancellation_erroris not 100% accurate: if some cancellation handling code fail, the error may be replaced to something else. For accurate detection of cancellation, use@async.is_being_cancelledinstead
v0.13.3
- add experimental JavaScript backend support. Features include:
- all IO-independent abstractions are available, including task group, timeout, async queue, semaphore etc.
- a new package,
moonbitlang/async/js_async, provides integration with JavaScript promise:- wait for JavaScript promise, with automatic cancellation support using
AbortController - export async MoonBit function as JavaScript promise, again with native cancellation support via
AbortSignal
- wait for JavaScript promise, with automatic cancellation support using
- add
@async.is_being_cancelledfor detecting whether current task is being cancelled. This is useful for avoiding dead loop for some code patterns, such as writing catch-all error handler inside loop body - ignore
SIGPIPE, so that writing to a closed pipe result in a normal error instead of crashing the program - some other bugfix
v0.13.2
- add
@io.Reader::read_some, which read a new chunk of data from the reader as soon as new data arrives. This is useful for iterating over a reader stream chunk-by-chunk - add
reuse_addroption for TCP/HTTP server. This is useful for testing and quick hacking, but should not be used in production - bugfix
v0.13.1
v0.13.0
- [breaking]
@io.Readeris now always buffered. End users can take benefit from this via the newread_untilAPI, which consumes input stream until a separator is reached. For end users this change should be non-breaking, but custom implementations of@io.Readerwill be broken (this is not encouraged, though). The type@io.BufferedReaderis no longer useful and is deprecated. - add new package
moonbitlang/async/cond_varfor condition variable. The type@cond_var.Condcan also be accessed via@async.CondVar. It supports a.waitoperation, as well as.signaloperation for waking up a single waker, and.broadcastfor waking up all waiters. See the API doc for more details - introduce
@io.pipe()and two new types@io.PipeRead&@io.PipeWrite, which implements fully user-space, un-buffered pipe. This is useful for testing and converting writer based function to reader.@pipe.pipe()is still useful for some complex process output collection task, but it may be deprecated in the future once we get replacement for that kind of tasks (e.g. merging output of multiple process) - add
@http.{get,put,post}_stream, which are streaming version of@http.{get,put,post}and allows lazily read/write response/request body. These API return a@http.Clientfor lazy IO, which must be manually closed. Though more verbose, this allows precise control of connection lifetime.
v0.12.0
- [breaking]
@fs.opendiris nowasync - add
@fs.symlinkfor creating symbolic link and@fs.chmodfor changing file permission - add
@fs.read_atand@fs.write_atfor reading/writing file at specific position, without modifying or depending on the global file pointer state. Seeking based API are deprecated in favor ofread_at/write_at - bug fix:
- fix incorrect behavior of
@io.BufferedReader::find{_opt}when target pattern span across multiple chunks of data - fix
@process.collect_outputhanging on large stderr - some MacOS systems do not have
fdatasync, so we avoid calling it on MacOS and usefsyncinstead - fix a race condition that may crash the runtime
- fix incorrect behavior of