Don't import/export chronos by default (#20)

Chronos support is optional and should not have to be imported in order
to use faststreams for non-async use cases, as doing so pollutes the
global namespace and slows down compilation.

`async` support must now explicitly be enabled with
-d:async_backend=chronos|asyncdispatch
This commit is contained in:
Jacek Sieka 2021-08-20 13:10:26 +02:00 • committed by GitHub
commit 3a0ab42573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 841 additions and 705 deletions

View file

@ -1,14 +1,25 @@
const
faststreams_async_backend {.strdefine.} = "chronos"
# To compile with async support, use `-d:async_backend=chronos|asyncdispatch`
async_backend {.strdefine.} = "none"
const
faststreams_async_backend {.strdefine.} = ""
when faststreams_async_backend != "":
{.fatal: "use `-d:async_backend` instead".}
type
CloseBehavior* = enum
waitAsyncClose
dontWaitAsyncClose
const debugHelpers* = defined(debugHelpers)
const
debugHelpers* = defined(debugHelpers)
fsAsyncSupport* = async_backend != "none"
when faststreams_async_backend == "chronos":
when async_backend == "none":
discard
elif async_backend == "chronos":
import
chronos
@ -18,10 +29,10 @@ when faststreams_async_backend == "chronos":
template fsAwait*(f: Future): untyped =
await f
elif faststreams_async_backend in ["std", "asyncdispatch"]:
elif async_backend in ["std", "asyncdispatch"]:
import
std/asyncdispatch
export
asyncdispatch
@ -36,7 +47,7 @@ elif faststreams_async_backend in ["std", "asyncdispatch"]:
type Duration* = int
else:
{.fatal: "Unrecognized network backend: " & faststreams_async_backend.}
{.fatal: "Unrecognized network backend: " & async_backend.}
when defined(danger):
template fsAssert*(x) = discard