Fork me on GitHub
Ahmed Hassan07:04:20

How I can get value inside promise? I want to save value in atom/var and give as an argument to a function.


(.then promise #(reset a %))

ūüĎć 4

Promises are async, you can't work with them in a sync manner.

ūüĎć 4
Ahmed Hassan09:04:29

How should I pass it to a function to process Promise's return value?


Call that function in .then.

ūüĎć 4

As soon as you encounter a promise, there's no longer a return value. There's a continuation, where everything must follow if it is to be sync'ed.

ūüĎć 4

Hi, I'm trying to run some Clojurescript tests with Shadow-cljs with the following config:

  {:target    :node-test
   :output-to "out/node-tests.js"
   :ns-regexp "-test$"
   :autorun   true}}
This all works, except when I require a namespace, which in turn requires [ajax.core :as ajax] I get this error:
TypeError: util.randomUUID is not a function
Tracing this back, it's a reference to the following This file is also in my build result .shadow-cljs/builds/test/dev/out/cljs-runtime/com.cognitect.transit.utils.js Anyone have an idea of what I'm doing wrong?


Just noticed another error, which is probably the reason for this: SHADOW import error /Users/kwrooijen/my-app/.shadow-cljs/builds/test/dev/out/cljs-runtime/com.cognitect.transit.handlers.js Not sure why this is happening though


there should be more to that error? or even multiple instances of that error? It is usually one error resulting in many others


Sorry, should've pasted this right away. Here's the complete stack

npx shadow-cljs compile test
shadow-cljs - config: /Users/kwrooijen/my-app/shadow-cljs.edn  cli version: 2.8.83  node: v10.16.3
[:test] Compiling ...
========= Running Tests =======================
SHADOW import error /Users/kwrooijen/my-app/.shadow-cljs/builds/test/dev/out/cljs-runtime/com.cognitect.transit.handlers.js

TypeError: util.randomUUID is not a function
    at /Users/kwrooijen/my-app/.shadow-cljs/builds/test/dev/out/cljs-runtime/com/cognitect/transit/handlers.js:36:9
    at (/Users/kwrooijen/my-app/out/node-tests.js:1122:6)
    at /Users/kwrooijen/my-app/.shadow-cljs/builds/test/dev/out/cljs-runtime/com/cognitect/transit/handlers.js:27:5
    at global.SHADOW_IMPORT (/Users/kwrooijen/my-app/out/node-tests.js:64:44)
    at /Users/kwrooijen/my-app/out/node-tests.js:2258:1
    at Object.<anonymous> (/Users/kwrooijen/my-app/out/node-tests.js:2:2)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
[:test] Build completed. (168 files, 10 compiled, 0 warnings, 3.54s)


strange. which transit version is this?


from shadow-cljs --cli-info

[com.cognitect/transit-cljs "0.8.256"]
  [com.cognitect/transit-js "0.8.846"]


sorry no clue why this is failing. works fine for me


only guess is that you have some kind of dependency conflict


works totally fine for me locally


maybe try wiping the .shadow-cljs/builds cache


Tried deleting that. I'll make a fresh project and try again. Thanks!

Quentin Le Guennec13:04:07

Hello, my cider session hangs when I start figwheel. I can't evaluate anything, RET inserts newline without re-printing the prompt.


Is it figwheel main with lein?


Does something like rxdb’s exist in the cljs world? I know re-frame gets around this with, but I was curious if there are any other front-end like databases that have this (Datascript? Pathom?).


Anybody here use reitit for routes? How do you get it to work with hot reloading with shadow-cljs?


If you're asking how not to lose state you created using def, you can use defonce instead:

Ahmed Hassan19:04:37

What really is the concept of goog.async.Deferred in Google Closure Library? Is it really like advanced form of Promises?


since ‚Äúpromises‚ÄĚ have similar, but varying interfaces and ideas in different languages and frameworks, I avoid describing other concepts in terms of them. Deferred and promises are tools used for handling asynchronous code. When it comes to asynchronous code, I really recommend CSP (Communicating Sequential Processes) as a foundation as it has a more theoretical basis, As an aside, both go‚Äôs async features and clojure.core.async use CSP as a basis as well


I just read the description, and I think Ahmed is right. Looks like a really useful feature of Deferred is that you can cancel them. You can't do that on promises.


generally, when comparing Deferred to Promise, Promise is about one asynchronous task (although some libraries/frameworks have promises do more). Deferred usually has extra tools for combining multiple asynchronous tasks and handling error states

Ahmed Hassan19:04:05

Many namespaces in Google Closure Library depend on Deffered. They're backbone of asynchrony here IMO.


for the google closure library, yes


there are lots of options for handling asynchrony if you’re using clojurescript though. for example

Ahmed Hassan19:04:35

I wanted to save Canvas as a PNG image to local filesystem, so I approached goog.fs where I saw Deffered very heavily used.

ūüĎć 4
Ahmed Hassan19:04:48

It seems Deferred already provides with what JS community is celebrating in the twitter thread you shared:


yea, that was my point


Probably Deferred was there before JS got Promises. There’s similar things in Python Twisted.

Ahmed Hassan06:04:09

@U7PBP4UVA do you consider Deferred feasible?


Not sure what you mean by feasible in this sense. I only meant that JS promises was kind of a late arrival. goog.async.Deferred was (probably, I never checked) there well before JS got Promises as even a 3rd-party library. These days native JS Promises have direct support in most engines, but the concept isn’t something new.


the wikipedia article is kinda interesting ( > The term promise was proposed in 1976 by and David Wise, and Peter Hibbard called it eventual. A somewhat similar concept future was introduced in 1977 in a paper by and > The terms future, promise, delay, and deferred are often used interchangeably, although some differences in usage between future and promise are treated below.

Ahmed Hassan07:04:14

By feasible I mean: what are trade offs of JS Promise when compared with Deferred?

Ahmed Hassan08:04:37

There's too. > NOTE: This class was created in anticipation of the built-in Promise type being standardized and implemented across browsers. Now that Promise is available in modern browsers, and is automatically polyfilled by the Closure Compiler, by default, most new code should use native `Promise` instead of `goog.Promise`. However, `goog.Promise` has the concept of cancellation which native Promises do not yet have. So code needing cancellation may still want to use `goog.Promise`. EDIT: Also and

ūüėģ 4
Ahmed Hassan08:04:49

Great definition of Promise from > A promise represents the eventual result of an asynchronous operation. The primary way of interacting with a promise is through its `then` method, which registers callbacks to receive either a promise’s eventual value or the reason why the promise cannot be fulfilled.


Hi, I'm running a shadow-cljs app, and getting the following error in my browser: WebSocket connection to '<ws://localhost:9631/ws/worker/app/d220add9-aa54-43e3-be71-b121ec13636f/e2fa1a2b-01cf-44e7-9bf0-c5db8cb75503/browser>' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED


And the shadow-cljs has stopped reloading, and I don't know what's causing this.


How do I even start to debug this, if there aren't any other errors in the console?


Well there's also this error: shadow-cljs: websocket error Event {isTrusted: true, type: "error", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} bubbles: false cancelBubble: false cancelable: false composed: false currentTarget: WebSocket {url: "<ws://localhost:9631/ws/worker/app/d220add9-aa54-43>…636f/e2fa1a2b-01cf-44e7-9bf0-c5db8cb75503/browser", readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …} defaultPrevented: false eventPhase: 0 isTrusted: true path: [] returnValue: true srcElement: WebSocket {url: "<ws://localhost:9631/ws/worker/app/d220add9-aa54-43>…636f/e2fa1a2b-01cf-44e7-9bf0-c5db8cb75503/browser", readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …} target: WebSocket {url: "<ws://localhost:9631/ws/worker/app/d220add9-aa54-43>…636f/e2fa1a2b-01cf-44e7-9bf0-c5db8cb75503/browser", readyState: 3, bufferedAmount: 0, onopen: ƒ, onerror: ƒ, …} timeStamp: 147976.1250000156 type: "error" proto__: Event


@pshar10 you might want to ask in the #shadow-cljs channel?

Mitch Dzugan23:04:36

Anyone familiar with wrapping defprotocol in a macro from clojurescript. This is the minimal repro of an issue I'm currently having:

# src/app/macros.cljc

(ns app.macros
  #?(:cljs (:require-macros [app.macros :refer [testproto]])))

   (defmacro testproto [proto nm args]
     `(defprotocol ~proto
        (~nm ~args))))
This macro works fine when used from clojure but when used from clojurescript like so
# src/app/core.cljs
(ns app.core (:require [app.macros :refer [testproto]]))

(testproto MyProtocol proto-method [b])
I get build error
Caused by: java.lang.Exception: Invalid protocol, MyProtocol received unexpected argument
	at cljs.core$defprotocol$fn__4490.invoke(core.cljc:2047)
	at cljs.core$defprotocol.invokeStatic(core.cljc:2032)
	at cljs.core$defprotocol.doInvoke(core.cljc:1989)
	at clojure.lang.RestFn.applyTo(
	at clojure.core$apply.invokeStatic(core.clj:669)
	at clojure.core$apply.invoke(core.clj:660)
	at cljs.analyzer$macroexpand_1_STAR_$fn__2556.invoke(analyzer.cljc:3879)
My guess would be this has something to do with the different defprotocol implementations in clojurescript vs clojure and the #?(:clj) reader making the clojurescript implementation try to use the clojure version but I even tried replacing defprotocol with cljs.core/defprotocol in the macro definition to see if I could get that to work from clojurescript but got the same error