Skip to content

Commit

Permalink
Don't import/export chronos by default (#20)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arnetheduck committed Aug 20, 2021
1 parent 5eb7fd0 commit 3a0ab42
Show file tree
Hide file tree
Showing 10 changed files with 876 additions and 740 deletions.
9 changes: 7 additions & 2 deletions faststreams.nimble
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mode = ScriptMode.Verbose

packageName = "faststreams"
version = "0.2.0"
version = "0.3.0"
author = "Status Research & Development GmbH"
description = "Nearly zero-overhead input/output streams for Nim"
license = "Apache License 2.0"
Expand All @@ -21,7 +21,12 @@ proc test(env, path: string) =
lang = getEnv"TEST_LANG"

exec "nim " & lang & " " & env &
" -r --hints:off --skipParentCfg " & path
" -d:async_backend=none -r --hints:off --skipParentCfg " & path
exec "nim " & lang & " " & env &
" -d:async_backend=chronos -r --hints:off --skipParentCfg " & path
# TODO std backend is broken / untested
# exec "nim " & lang & " " & env &
# " -d:async_backend=chronos -r --hints:off --skipParentCfg " & path

task test, "Run all tests":
test "-d:debug --threads:on", "tests/all_tests"
Expand Down
23 changes: 17 additions & 6 deletions faststreams/async_backend.nim
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions faststreams/buffers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type
maxBufferedBytes*: Natural

queue*: Deque[PageRef]
waitingReader*: Future[void]
waitingWriter*: Future[void]
when fsAsyncSupport:
waitingReader*: Future[void]
waitingWriter*: Future[void]

eofReached*: bool
fauxEofPos*: Natural
Expand Down
Loading

0 comments on commit 3a0ab42

Please sign in to comment.