diff options
author | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-01-03 21:47:59 +0200 |
---|---|---|
committer | Yuriy Glukhov <yuriy.glukhov@gmail.com> | 2018-01-05 16:40:51 +0200 |
commit | c93655e8b492dacbf35e5152e716035e112c899f (patch) | |
tree | f0b62b7039a7dd53bfa7456312252bbcd6c61c24 /tests/async | |
parent | 67ac1aef594a328997fc9d3f6b36a73fc583f2ba (diff) | |
download | Nim-c93655e8b492dacbf35e5152e716035e112c899f.tar.gz |
Unify async macro and futures for js and native targets
Diffstat (limited to 'tests/async')
-rw-r--r-- | tests/async/config.nims | 2 | ||||
-rw-r--r-- | tests/async/tjsandnativeasync.nim | 30 |
2 files changed, 30 insertions, 2 deletions
diff --git a/tests/async/config.nims b/tests/async/config.nims deleted file mode 100644 index 97c2e0aa4..000000000 --- a/tests/async/config.nims +++ /dev/null @@ -1,2 +0,0 @@ -when defined(upcoming): - patchFile("stdlib", "asyncdispatch", "$lib/upcoming/asyncdispatch") 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() |