mirror of
https://github.com/status-im/nim-chronos.git
synced 2025-02-21 23:48:15 +00:00
This avoids copies here and there throughout the pipeline - ie `copyString` and friends can often be avoided when moving things into and out of futures Annoyingly, one has to sprinkle the codebase liberally with `sink` and `move` for the pipeline to work well - sink stuff _generally_ works better in orc/arc Looking at nim 1.6/refc, sink + local variable + move generates the best code: msg directly: ```nim T1_ = (*colonenv_).msg1; (*colonenv_).msg1 = copyStringRC1(msg); ``` local copy without move: ```nim T60_ = (*colonenv_).localCopy1; (*colonenv_).localCopy1 = copyStringRC1(msg); ``` local copy with move: ```nim asgnRef((void**) (&(*colonenv_).localCopy1), msg); ``` Annoyingly, sink is also broken for refc+literals as it tries to changes the refcount of the literal as part of the move (which shouldn't be happening, but here we are), so we have to use a hack to find literals and avoid moving them.
Chronos - An efficient library for asynchronous programming
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
- MIT license: LICENSE-MIT or http://opensource.org/licenses/MIT
or
- Apache License, Version 2.0, (LICENSE-APACHEv2 or http://www.apache.org/licenses/LICENSE-2.0)
at your option. These files may not be copied, modified, or distributed except according to those terms.
Description
Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/
Languages
Nim
99.7%
C
0.2%