Conversation
| "name": "your-project-name", | ||
| "version": "0.1.0", | ||
| "deps": { | ||
| "moonbitlang/async": "0.8.0" |
There was a problem hiding this comment.
too old. Can this be updated automatically?
| } | ||
| ``` | ||
|
|
||
| **Key Change**: Now use `async fn main` directly, no longer need `@async.with_event_loop` wrapper. |
|
|
||
| ```moonbit | ||
| ///| | ||
| async fn timeout_examples() -> Unit { |
| } | ||
| ``` | ||
|
|
||
| ## Structured Concurrency and Task Groups |
There was a problem hiding this comment.
I think we need some precise textual description of the semantic here. Maybe just copy-and-paste the relevant parts from the docstring of with_task_group & spawn_bg?
| defer file.close() | ||
|
|
||
| // Write data | ||
| file.write_string("Line 1\nLine 2\nLine 3\n",encoding=@io.UTF8) |
| async fn concurrency_patterns() -> Unit { | ||
| // Limit concurrency | ||
| @async.with_task_group(fn(group) { | ||
| let semaphore = @async.Queue::new() |
There was a problem hiding this comment.
we now have native moonbitlang/async/semaphore
| for i in 0..<20 { | ||
| group.spawn_bg(fn() { | ||
| let _permit = semaphore.get() // Acquire permit | ||
| defer semaphore.put(()) // Release permit |
| // Task group ensures all tasks complete | ||
| }) | ||
| } | ||
| ``` |
There was a problem hiding this comment.
we enforce proper task lifecycle management via with_task_group, so this section does not make a lot of sense
| ```moonbit | ||
| ///| | ||
| async fn logging_example() -> Unit { | ||
| @pipe.stderr.write("Starting request processing\n") |
| 1. **Use `inspect()` for Assertions**: MoonBit's `inspect()` function is perfect for testing async results | ||
| 2. **Test Timing Behavior**: Use `@async.sleep()` to simulate realistic timing scenarios | ||
| 3. **Test Error Conditions**: Always test timeout, cancellation, and error propagation | ||
| 4. **Use StringBuilder for Logging**: Capture execution order and verify concurrent behavior |
There was a problem hiding this comment.
I remember that we have a native @test.Test type for this, which should be more idiomatic. Maybe just remove this one?
|
Since the async package is still changing a lot, I think one option to keep things up-to-date is:
|
No description provided.