Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
feat: add nbb.core await example
Browse files Browse the repository at this point in the history
  • Loading branch information
aisamu committed Sep 29, 2022
1 parent 88fa042 commit 8fe7ce2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
21 changes: 17 additions & 4 deletions readme.org
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,33 @@ Loaded module
Loaded main.cljs


$> nbb src/main-imp-del-async.cljs
$> nbb src/main-imp-async.cljs
;; Fails: Imperative delayed async import
Loaded main.cljs
Cannot find module '/Users/aisamu/code/node/nbb-relative-async-imports/src/helper.mjs'
Require stack:
- /Users/aisamu/code/node/nbb-relative-async-imports/src/main-imp-del-async.cljs
- /Users/aisamu/code/node/nbb-relative-async-imports/src/main-imp-async.cljs


$> nbb src/main-imp-async.cljs
$> nbb src/main-imp-del-async.cljs
;; Fails: Imperative delayed async import
Loaded main.cljs
Cannot find module '/Users/aisamu/code/node/nbb-relative-async-imports/src/helper.mjs'
Require stack:
- /Users/aisamu/code/node/nbb-relative-async-imports/src/main-imp-async.cljs
- /Users/aisamu/code/node/nbb-relative-async-imports/src/main-imp-del-async.cljs


$> nbb src/main-imp-async-awaited.cljs
;; Works: Imperative do-delayed async import awaited
Loaded helper.mjs
Loaded module
Loaded main.cljs


$> nbb src/main-imp-del-async-awaited.cljs
;; Half-works: Imperative promise-delayed async import awaited
Loaded helper.mjs
Loaded module
#+end_src

#+begin_quote
Expand Down
10 changes: 10 additions & 0 deletions src/main-imp-async-awaited.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; Works: Imperative do-delayed async import awaited
(ns main
(:require [promesa.core :as p]
[nbb.core :refer [await]]))

;; It tries to load helper.mjs from '/src/helper.mjs'
;; instead of '/src/modules/module/helper.mjs'
(await (p/do (require '[modules.module.core])))

(println "Loaded main.cljs")
10 changes: 10 additions & 0 deletions src/main-imp-del-async-awaited.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; Half-works: Imperative promise-delayed async import awaited
(ns main
(:require [promesa.core :as p]
[nbb.core :refer [await]]))

(await (js/Promise. #(require '[modules.module.core])))

;; Never gets executed
(println "Loaded main.cljs")
(js/console.log "js: Loaded main.cljs")

0 comments on commit 8fe7ce2

Please sign in to comment.