Go to file
Jaremy Creechley 61ff2594d3
Feature: handle seq[byte] and strings using openArray's and memory retention (#7)
Limited support for passing seq's of bytes and strings to tasklets using openArray
2024-02-16 17:13:59 -07:00
src Feature: handle seq[byte] and strings using openArray's and memory retention (#7) 2024-02-16 17:13:59 -07:00
tests Feature: handle seq[byte] and strings using openArray's and memory retention (#7) 2024-02-16 17:13:59 -07:00
.gitignore Initial Setup (#1) 2024-02-14 22:14:20 -07:00
README.md Update README.md 2024-02-14 22:23:12 -07:00
apatheia.nimble Feature: handle seq[byte] and strings using openArray's and memory retention (#7) 2024-02-16 17:13:59 -07:00
build.nims Feature: handle seq[byte] and strings using openArray's and memory retention (#7) 2024-02-16 17:13:59 -07:00
config.nims Feature: handle seq[byte] and strings using openArray's and memory retention (#7) 2024-02-16 17:13:59 -07:00

README.md

Apatheia

Apatheia (Greek: ἀπάθεια; from a- "without" and pathos "suffering" or "passion"), in Stoicism, refers to a state of mind in which one is not disturbed by the passions. It might better be translated by the word equanimity than the word indifference.

The goal of the apatheia library is to provide a painless, suffering free way of using multi-threading with async in Nim.

The main modules are:

  • queues - queues with support for async signals
  • jobs - macro and utilities for submitting jobs to a taskpool
  • tasks - convenience wrapper to turn a proc into a job with a simple API

Example usage:

import taskpools
import apatheia/tasks

proc addNums(a, b: float): float {.asyncTask.} =
  os.sleep(50)
  return a + b

proc addNumValues(vals: openArray[float]): float {.asyncTask.} =
  os.sleep(100)
  result = 0.0
  for x in vals:
    result += x

suite "async tests":
  var tp = Taskpool.new(num_threads = 2) # Default to the number of hardware threads.

  asyncTest "test addNums":
    var jobs = newJobQueue[float](taskpool = tp)
    let res = await jobs.submit(addNums(1.0, 2.0,))
    check res == 3.0

  asyncTest "test addNumValues":
    var jobs = newJobQueue[float](taskpool = tp)
    let args = @[1.0, 2.0, 3.0]
    let res = await jobs.submit(addNumValues(args))
    check res == 6.0

Future Goals:

  • support orc and refc
    • refc may require extra copying for data
  • use event queues (e.g. channels) to/from thread pool
    • make it easy to monitor and debug queue capacity
    • only use minimal AsyncFD handles
    • lessen pressure on the main chronos futures pending queue
  • support backpressure at futures level
  • benchmarking overhead
  • special support for seq[byte]'s and strings with zero-copy
    • implement special but limited support zero-copy arguments on refc