2020-07-13 17:59:11 +02:00
# Chronos - An efficient library for asynchronous programming
2019-02-06 16:43:27 +01:00
2023-09-05 13:48:09 +03:00
[![Github action ](https://github.com/status-im/nim-chronos/workflows/CI/badge.svg )](https://github.com/status-im/nim-chronos/actions/workflows/ci.yml)
2018-09-04 21:36:14 -06:00
[![License: Apache ](https://img.shields.io/badge/License-Apache%202.0-blue.svg )](https://opensource.org/licenses/Apache-2.0)
[![License: MIT ](https://img.shields.io/badge/License-MIT-blue.svg )](https://opensource.org/licenses/MIT)
2018-09-04 21:27:01 -06:00
![Stability: experimental ](https://img.shields.io/badge/stability-experimental-orange.svg )
2018-05-22 01:15:34 +03:00
2019-05-20 17:43:23 +02:00
## Introduction
2021-03-20 08:12:35 +01:00
Chronos is an efficient [async/await ](https://en.wikipedia.org/wiki/Async/await ) framework for Nim. Features include:
2023-11-08 15:12:32 +01:00
* Asynchronous socket and process I/O
2021-03-20 08:12:35 +01:00
* HTTP server with SSL/TLS support out of the box (no OpenSSL needed)
* Synchronization primitivies like queues, events and locks
2023-11-08 15:12:32 +01:00
* Cancellation
* Efficient dispatch pipeline with excellent multi-platform support
2023-11-15 09:06:37 +01:00
* Exceptional error handling features, including `raises` tracking
2018-05-30 06:34:58 +03:00
2023-11-15 09:06:37 +01:00
## Getting started
2021-03-20 08:12:35 +01:00
2023-11-15 09:06:37 +01:00
Install `chronos` using `nimble` :
2018-05-29 02:35:15 +03:00
2021-03-20 08:12:35 +01:00
```text
2023-02-16 21:27:31 +01:00
nimble install chronos
2018-05-30 06:32:47 +03:00
```
2021-03-20 08:12:35 +01:00
or add a dependency to your `.nimble` file:
```text
requires "chronos"
2018-05-30 06:32:47 +03:00
```
2018-05-29 02:35:15 +03:00
2023-11-15 09:06:37 +01:00
and start using it:
2023-02-16 21:27:31 +01:00
```nim
2023-10-25 15:16:10 +02:00
import chronos/apps/http/httpclient
2023-11-15 09:06:37 +01:00
proc retrievePage(uri: string): Future[string] {.async.} =
# Create a new HTTP session
let httpSession = HttpSessionRef.new()
2023-02-16 21:27:31 +01:00
try:
2023-11-15 09:06:37 +01:00
# 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())
2023-02-16 21:27:31 +01:00
2023-11-15 09:06:37 +01:00
echo waitFor retrievePage(
"https://raw.githubusercontent.com/status-im/nim-chronos/master/README.md")
2023-02-16 21:27:31 +01:00
```
2023-11-15 09:06:37 +01:00
## Documentation
2021-11-08 15:17:37 +01:00
2023-11-15 09:06:37 +01:00
See the [user guide ](https://status-im.github.io/nim-chronos/ ).
2021-11-08 15:17:37 +01:00
2023-11-15 09:06:37 +01:00
## Projects using `chronos`
2021-11-08 15:17:37 +01:00
2023-11-15 09:06:37 +01:00
* [libp2p ](https://github.com/status-im/nim-libp2p ) - Peer-to-Peer networking stack implemented in many languages
* [presto ](https://github.com/status-im/nim-presto ) - REST API framework
* [Scorper ](https://github.com/bung87/scorper ) - Web framework
* [2DeFi ](https://github.com/gogolxdong/2DeFi ) - Decentralised file system
* [websock ](https://github.com/status-im/nim-websock/ ) - WebSocket library with lots of features
2023-03-31 07:35:04 +02:00
2023-11-15 09:06:37 +01:00
`chronos` is available in the [Nim Playground ](https://play.nim-lang.org/#ix=2TpS )
2023-03-31 07:35:04 +02:00
2023-11-15 09:06:37 +01:00
Submit a PR to add yours!
2023-03-31 07:35:04 +02:00
2018-05-30 06:32:47 +03:00
## TODO
* Multithreading Stream/Datagram servers
2020-07-13 17:59:11 +02:00
2019-05-20 17:43:23 +02:00
## 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.
2018-05-29 02:35:15 +03:00
2021-03-20 08:12:35 +01:00
`chronos` follows the [Status Nim Style Guide ](https://status-im.github.io/nim-style-guide/ ).
2018-09-04 21:36:14 -06:00
## License
2018-09-05 12:45:22 -06:00
Licensed and distributed under either of
* MIT license: [LICENSE-MIT ](LICENSE-MIT ) or http://opensource.org/licenses/MIT
2019-01-02 14:53:00 +01:00
or
* Apache License, Version 2.0, ([LICENSE-APACHEv2 ](LICENSE-APACHEv2 ) or http://www.apache.org/licenses/LICENSE-2.0)
2018-09-04 21:36:14 -06:00
2020-07-13 17:59:11 +02:00
at your option. These files may not be copied, modified, or distributed except according to those terms.