Chronos - An efficient library for asynchronous programming https://status-im.github.io/nim-chronos/
Go to file
Etan Kissling 5dfa3fd7fa
fix conversion error with `or` on futures with `{.async: (raises: []).}` (#515)
```nim
import chronos

proc f(): Future[void] {.async: (raises: []).} =
  discard

discard f() or f() or f()
```

```
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nim-chronos/chronos/internal/raisesfutures.nim(145, 44) union
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nimbus-build-system/vendor/Nim/lib/core/macros.nim(185, 28) []
/Users/etan/Documents/Repos/nimbus-eth2/test.nim(6, 13) template/generic instantiation of `or` from here
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nim-chronos/chronos/internal/asyncfutures.nim(1668, 39) template/generic instantiation of `union` from here
/Users/etan/Documents/Repos/nimbus-eth2/vendor/nimbus-build-system/vendor/Nim/lib/core/macros.nim(185, 28) Error: illegal conversion from '-1' to '[0..9223372036854775807]'
```

Fix by checking for `void` before trying to access `raises`
2024-03-05 13:53:12 +01:00
.github/workflows Update docs (#480) 2023-12-01 12:33:28 +01:00
chronos fix conversion error with `or` on futures with `{.async: (raises: []).}` (#515) 2024-03-05 13:53:12 +01:00
docs Minimal threading docs (#493) 2024-02-14 08:27:09 +01:00
tests Strip debugging echo in threadsync tests. 2024-02-14 14:09:01 +02:00
.gitignore move docs to docs (#466) 2023-11-15 09:06:37 +01:00
LICENSE-APACHEv2 Rebrand Asyncdispatch2 to Chronos [WIP] (#20) 2019-02-06 15:49:11 +01:00
LICENSE-MIT Rebrand Asyncdispatch2 to Chronos [WIP] (#20) 2019-02-06 15:49:11 +01:00
README.md move docs to docs (#466) 2023-11-15 09:06:37 +01:00
chronos.nim move docs to docs (#466) 2023-11-15 09:06:37 +01:00
chronos.nimble Add `--mm:refc` to `libbacktrace` test. (#505) 2024-02-14 19:23:15 +02:00
config.nims Add nimRawSetjmp define to config.nims (#285) 2022-06-14 01:02:33 +03:00
nim.cfg simplify tests (#469) 2023-11-13 10:54:37 +01:00

README.md

Chronos - An efficient library for asynchronous programming

Github action License: Apache License: MIT Stability: experimental

Introduction

Chronos is an efficient async/await framework for Nim. Features include:

  • Asynchronous socket and process I/O
  • HTTP server with SSL/TLS support out of the box (no OpenSSL needed)
  • Synchronization primitivies like queues, events and locks
  • Cancellation
  • Efficient dispatch pipeline with excellent multi-platform support
  • Exceptional error handling features, including raises tracking

Getting started

Install chronos using nimble:

nimble install chronos

or add a dependency to your .nimble file:

requires "chronos"

and start using it:

import chronos/apps/http/httpclient

proc retrievePage(uri: string): Future[string] {.async.} =
  # Create a new HTTP session
  let httpSession = HttpSessionRef.new()
  try:
    # Fetch page contents
    let resp = await httpSession.fetch(parseUri(uri))
    # Convert response to a string, assuming its encoding matches the terminal!
    bytesToString(resp.data)
  finally: # Close the session
    await noCancel(httpSession.closeWait())

echo waitFor retrievePage(
  "https://raw.githubusercontent.com/status-im/nim-chronos/master/README.md")

Documentation

See the user guide.

Projects using chronos

  • libp2p - Peer-to-Peer networking stack implemented in many languages
  • presto - REST API framework
  • Scorper - Web framework
  • 2DeFi - Decentralised file system
  • websock - WebSocket library with lots of features

chronos is available in the Nim Playground

Submit a PR to add yours!

TODO

  • Multithreading Stream/Datagram servers

Contributing

When submitting pull requests, please add test cases for any new features or fixes and make sure nimble test is still able to execute the entire test suite successfully.

chronos follows the Status Nim Style Guide.

License

Licensed and distributed under either of

or

at your option. These files may not be copied, modified, or distributed except according to those terms.