summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorYuriy Glukhov <yuriy.glukhov@gmail.com>2018-01-03 21:47:59 +0200
committerYuriy Glukhov <yuriy.glukhov@gmail.com>2018-01-05 16:40:51 +0200
commitc93655e8b492dacbf35e5152e716035e112c899f (patch)
treef0b62b7039a7dd53bfa7456312252bbcd6c61c24 /lib
parent67ac1aef594a328997fc9d3f6b36a73fc583f2ba (diff)
downloadNim-c93655e8b492dacbf35e5152e716035e112c899f.tar.gz
Unify async macro and futures for js and native targets
Diffstat (limited to 'lib')
-rw-r--r--lib/js/asyncjs.nim4
-rw-r--r--lib/pure/async.nim6
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/js/asyncjs.nim b/lib/js/asyncjs.nim
index ec410ee39..3c488dcfe 100644
--- a/lib/js/asyncjs.nim
+++ b/lib/js/asyncjs.nim
@@ -139,3 +139,7 @@ macro async*(arg: untyped): untyped =
 proc newPromise*[T](handler: proc(resolve: proc(response: T))): Future[T] {.importcpp: "(new Promise(#))".}
   ## A helper for wrapping callback-based functions
   ## into promises and async procedures
+
+proc newPromise*(handler: proc(resolve: proc())): Future[void] {.importcpp: "(new Promise(#))".}
+  ## A helper for wrapping callback-based functions
+  ## into promises and async procedures
diff --git a/lib/pure/async.nim b/lib/pure/async.nim
new file mode 100644
index 000000000..97b29f81d
--- /dev/null
+++ b/lib/pure/async.nim
@@ -0,0 +1,6 @@
+when defined(js):
+    import asyncjs
+    export asyncjs
+else:
+    import asyncmacro, asyncfutures
+    export asyncmacro, asyncfutures