From c93655e8b492dacbf35e5152e716035e112c899f Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 3 Jan 2018 21:47:59 +0200 Subject: Unify async macro and futures for js and native targets --- tests/async/tjsandnativeasync.nim | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/async/tjsandnativeasync.nim (limited to 'tests/async/tjsandnativeasync.nim') 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() -- cgit 1.4.1-2-gfad0