mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
31 lines
600 B
Nim
31 lines
600 B
Nim
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()
|