diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-01-18 11:40:30 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-01-18 11:40:30 +0100 |
commit | 090d22c71518babf662e55e971f9382e0d993052 (patch) | |
tree | 1218468e312482cd6f9d1f00396b9806583a5238 /tests/async/tjsandnativeasync.nim | |
parent | 6a2b57b4aac7d1a411bb8782523c3094774c4b09 (diff) | |
parent | 27aab0be162de4cca6132b46c12d98ce9c83d60e (diff) | |
download | Nim-090d22c71518babf662e55e971f9382e0d993052.tar.gz |
Merge branch 'devel' of github.com:nim-lang/Nim into devel
Diffstat (limited to 'tests/async/tjsandnativeasync.nim')
-rw-r--r-- | tests/async/tjsandnativeasync.nim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/async/tjsandnativeasync.nim b/tests/async/tjsandnativeasync.nim new file mode 100644 index 000000000..45839899f --- /dev/null +++ b/tests/async/tjsandnativeasync.nim @@ -0,0 +1,30 @@ +discard """ + output: '''hi +bye''' +""" + +import async, times +when defined(js): + proc sleepAsync(t: int): Future[void] = + var promise = newPromise() do(resolve: proc()): + {.emit: """ + setTimeout(function(){ + `resolve`(); + }, `t`); + """.} + result = promise +else: + from asyncdispatch import sleepAsync, waitFor + +proc foo() {.async.} = + echo "hi" + var s = epochTime() + await sleepAsync(500) + var e = epochTime() + doAssert(e - s > 0.1) + echo "bye" + +when defined(js): + discard foo() +else: + waitFor foo() |