NagyZoltanPeter 35a33adc98
feat: make Persistence interface async (#69)
* feat: make Persistence interface async

The 14 Persistence proc fields now return Future[...] with
{.async: (raises: []), gcsafe.}, allowing real I/O backends (SQLite,
encrypted file, network) to suspend rather than block the Chronos event
loop the manager runs on.

Propagates through:
- ReliabilityManager.lock: system.Lock -> chronos.AsyncLock. Acquired
  across awaits cleanly; matches the single-threaded Chronos worker the
  FFI uses. Multi-OS-thread use is now explicitly the caller's
  responsibility.
- sds_utils + sds.nim public API procs (wrapOutgoingMessage,
  unwrapReceivedMessage, markDependenciesMet, setCallbacks,
  resetReliabilityManager, cleanup, ensureChannel, removeChannel, the
  getter snapshots, etc.) are now async.
- FFI request handlers in library/sds_thread/... await the new API.
- Tests converted via an asyncTest template that wraps each test body
  in an async proc; setup/teardown use waitFor for their single async
  call (ensureChannel / cleanup).

Lock scope is preserved exactly: the same call sites that held the
kernel Lock today hold AsyncLock now -- no new locking added.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor: drop asyncSpawn, add asyncSetup/asyncTeardown

Three asyncSpawn usages removed:

- sds.nim startPeriodicTasks: stored the periodic-task futures on
  ReliabilityManager (new field `periodicTasks: seq[FutureBase]`) so
  cleanup can cancel them on shutdown instead of leaking the loops
  against a cleared manager.
- library/sds_thread/sds_thread.nim: fireSync moved BEFORE processing,
  then `await SdsThreadRequest.process(...)` instead of asyncSpawn'ing
  it. Aligns the worker with the SP-channel + lock assumption that
  there are no concurrent requests; caller throughput is unchanged
  because the caller only waits for receipt (fireSync), not processing.
- tests TestBus repair callback: replaced asyncSpawn(deliverExcept...)
  with an explicit pending-delivery queue drained by `bus.drain()`.
  Integration tests no longer rely on `sleepAsync(10ms)` to let
  spawned deliveries finish — they await drain instead.

Tests also pick up an asyncSetup/asyncTeardown pair (tests/async_unittest.nim)
so suite fixtures can `await` directly. All `waitFor` in setup/teardown
blocks is gone; only the top-level asyncTest wrapper still uses waitFor
(once, to drive the async proc to completion).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* Correctly propagate error hidden by new async move

* Correctly handle future cancellation exceptions, +some housekeeping

* Apply suggestion from @Ivansete-status

Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>

* Stylistics, async default implication addressed, nph style run

* Remove leaking CancelledFuture from public facing + as a consequence it is tuneled into handling CatchableError everywhere

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
2026-05-25 22:30:15 +02:00
2026-04-10 14:23:30 +02:00
2026-04-10 14:23:30 +02:00
2026-04-10 14:23:30 +02:00
2026-02-03 19:05:46 +00:00

nim-sds

Nim implementation of the e2e reliability protocol.

Prerequisites

  • Nix package manager

Quick start

git clone https://github.com/logos-messaging/nim-sds.git
cd nim-sds

# Build the shared library
nix build '.#libsds'

# Run tests
nix develop --command nimble test

Building

Desktop

nix build --print-out-paths '.#libsds'

Android

nix build --print-out-paths '.#libsds-android-arm64'
nix build --print-out-paths '.#libsds-android-amd64'
nix build --print-out-paths '.#libsds-android-x86'
nix build --print-out-paths '.#libsds-android-arm'

iOS

nix build --print-out-paths '.#libsds-ios'
Development shell

Enter the dev shell:

nix develop

Build using nimble tasks:

# Dynamic library (auto-detects OS)
nimble libsdsDynamicMac    # macOS
nimble libsdsDynamicLinux  # Linux
nimble libsdsDynamicWindows # Windows

# Static library
nimble libsdsStaticMac     # macOS
nimble libsdsStaticLinux   # Linux
nimble libsdsStaticWindows # Windows

Run tests:

nimble test

The built library is output to build/.

Android (without Nix)

Download the latest Android NDK:

cd ~
wget https://dl.google.com/android/repository/android-ndk-r27c-linux.zip
unzip android-ndk-r27c-linux.zip

Add to ~/.bashrc:

export ANDROID_NDK_ROOT=$HOME/android-ndk-r27c
export PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

Then build:

ARCH=arm64 nimble libsdsAndroid
Architecture Command
arm64 ARCH=arm64 nimble libsdsAndroid
amd64 ARCH=amd64 nimble libsdsAndroid
x86 ARCH=x86 nimble libsdsAndroid

The library is output to build/libsds.so.

Dependency management

Dependencies are managed by Nimble and pinned via nimble.lock.

To set up dependencies locally:

nimble setup -l

To update dependencies:

nimble lock

After updating nimble.lock, the Nix outputHash in nix/deps.nix must be recalculated by running nix build and updating the hash from the error output.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Description
Nim implementation of the e2e reliability protocol
Readme
Languages
Nim 91.9%
Nix 5.9%
Shell 1.5%
C 0.7%