From 632788e8e3e9849f6b0c9da867a1bf5c8f938e57 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Tue, 3 Dec 2024 17:17:14 +0800 Subject: [PATCH] fix(rtc): delete-graph return a promise now --- src/main/frontend/common/async_util.cljc | 87 ++++++++++++++---------- src/main/frontend/components/repo.cljs | 19 +++--- 2 files changed, 61 insertions(+), 45 deletions(-) diff --git a/src/main/frontend/common/async_util.cljc b/src/main/frontend/common/async_util.cljc index 0487204ae1a..2d5b1dd60f5 100644 --- a/src/main/frontend/common/async_util.cljc +++ b/src/main/frontend/common/async_util.cljc @@ -3,7 +3,8 @@ namespaces. See also: https://gist.github.com/vvvvalvalval/f1250cec76d3719a8343" #?(:cljs (:require [cljs.core.async.impl.channels :refer [ManyToManyChannel]] [clojure.core.async :as async] - [logseq.common.util :as common-util]))) + [logseq.common.util :as common-util] + [promesa.core :as p]))) #?(:cljs (defn throw-err @@ -14,6 +15,20 @@ [port] `(throw-err (cljs.core.async/p + "Converts a Core.async channel to a Promise" + [chan] + (let [d (p/deferred)] + (if chan + (async/go + (let [result (async/> (conj coll e) - distinct-key-fn (common-util/distinct-by distinct-key-fn) - true vec)) - (recur timeout-ch coll))) + (some? e) + (let [filter-v (filter-fn e) + filter-v* (if (instance? ManyToManyChannel filter-v) + (async/> (conj coll e) + distinct-key-fn (common-util/distinct-by distinct-key-fn) + true vec)) + (recur timeout-ch coll))) - (or stop + (or stop ;; got nil from in-ch, means in-ch is closed ;; so we stop the whole go-loop - (nil? e)) - (async/close! ch)))) - ch))) + (nil? e)) + (async/close! ch)))) + ch))) diff --git a/src/main/frontend/components/repo.cljs b/src/main/frontend/components/repo.cljs index 6797fa3264a..1c1ff1e9026 100644 --- a/src/main/frontend/components/repo.cljs +++ b/src/main/frontend/components/repo.cljs @@ -1,7 +1,7 @@ (ns frontend.components.repo - (:require [cljs.core.async :as async :refer [p (file-sync/