Skip to content

feat: Spinner should keep spinning while process is running - #6

Merged
tkolleh merged 11 commits into
mainfrom
fp
Mar 14, 2026
Merged

feat: Spinner should keep spinning while process is running#6
tkolleh merged 11 commits into
mainfrom
fp

Conversation

@tkolleh

@tkolleh tkolleh commented Mar 14, 2026

Copy link
Copy Markdown
Owner

Summary

This PR transitions the roda.lua library from a synchronous, blocking architecture to a fully asynchronous, non-blocking architecture using luv (libuv bindings for Lua). This ensures that the terminal spinner animates smoothly in the background while child processes execute, without freezing the Lua runtime.

Key Changes

  • Asynchronous Timers: Replaced manual system.gettime() checks and blocking while loops with uv.new_timer(). The spinner now renders frames automatically in the background event loop.
  • Non-Blocking Child Processes: Implemented Spinner:execute(command, args) using uv.spawn. This allows child processes to run concurrently without halting the main Lua thread.
  • Async Stream Handling: Standard output (stdout) from child processes is now captured asynchronously via uv.read_start(), preventing memory overflow and blocking during long-running commands.
  • Functional Bracket Pattern: Introduced a reusable async_bracket utility (Continuation-Passing Style) in roda.util. This guarantees safe acquisition and release of libuv resources (timers, pipes, process handles), preventing memory leaks even if errors occur.
  • Event Loop Integration: Added roda.run() to expose the libuv event loop, allowing the script to wait for all asynchronous tasks to complete.

Benefits

  • Smooth Animations: The spinner no longer stutters or stops when waiting for a process to finish.
  • Performance: Multi-platform asynchronous I/O natively supported by libuv (epoll, kqueue, IOCP).
  • Robustness: The functional bracket pattern ensures that all C-level resources are safely closed, eliminating potential memory leaks.
  • Composability: The Continuation-Passing Style (CPS) API sets the foundation for future functional enhancements like Promises or Task monads.

@tkolleh
tkolleh marked this pull request as ready for review March 14, 2026 09:13
@tkolleh
tkolleh merged commit 365c955 into main Mar 14, 2026
2 checks passed
@tkolleh tkolleh mentioned this pull request Mar 14, 2026
tkolleh added a commit that referenced this pull request Apr 3, 2026
* fix: Use lux for demo script

* feat: Make it async

* build: add lefthook configuration

* docs: simplify readme and add async usage

* docs(util): add proper comments to bracket function

* docs(init): add proper comments to functions

* test: add simple async test

* fix: ignore unused err argument in uv.read_start callback

* build: add linter to pre-commit hook

* Delete spec/simple_spec.lua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant