Back
sync (clj)
(source)macro
(sync flags-ignored-for-now & body)
transaction-flags => TBD, pass nil for now
Runs the exprs (in an implicit do) in a transaction that encompasses
exprs and any nested calls. Starts a transaction if none is already
running on this thread. Any uncaught exception will abort the
transaction and flow out of sync. The exprs may be run more than
once, but any effects on Refs will be atomic.
Examples
logseq/logseq
(ns frontend.pubsub
"All mults and pubs are collected to this ns.
vars with suffix '-mult' is a/Mult, use a/tap and a/untap on them. used by event subscribers
vars with suffix '-pub' is a/Pub, use a/sub and a/unsub on them. used by event subscribers
vars with suffix '-ch' is chan used by event publishers."
{:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}}
#?(:cljs (:require-macros [frontend.pubsub :refer [def-mult-or-pub chan-of]]))
(:require [clojure.core.async :as a :refer [chan mult pub]]
[clojure.core.async.impl.protocols :as ap]
[malli.core :as m]
[malli.dev.pretty :as mdp]
[clojure.pprint :as pp]))
(def-mult-or-pub sync-events
"file-sync events"
[:map
[:event [:enum
:created-local-version-file
:finished-local->remote
:finished-remote->local
:start
:pause
:resume
:exception-decrypt-failed
:remote->local-full-sync-failed
:local->remote-full-sync-failed
:get-remote-graph-failed
:get-deletion-logs-failed
:get-remote-all-files-failed]]
[:data :map]]
:topic-fn :event
:ch-buffer (a/sliding-buffer 10))
metosin/compojure-api
(ns example.handler
"Asynchronous compojure-api application."
(:require [compojure.api.sweet :refer :all]
[ring.util.http-response :refer :all]
[manifold.deferred :as d]
[clojure.core.async :as async]
compojure.api.async))
(GET "/divide" []
:return {:result Float}
:query-params [x :- Long, y :- Long]
:summary "divide two numbers together"
(async/go (ok {:result (float (/ x y))}))))
clj-commons/manifold
(ns manifold.stream.async
{:no-doc true}
(:require
[manifold.deferred :as d]
[clojure.core.async :as a]
[manifold.stream
[graph :as g]
[core :as s]]
[manifold
[executor :as executor]
[utils :as utils]])
(:import
[java.util.concurrent.atomic
AtomicReference]))
(s/def-source CoreAsyncSource
[ch ^AtomicReference last-take]
(description [this]
{:source? true
:drained? (s/drained? this)
:type "core.async"})
;; if I don't take this out of the goroutine, core.async OOMs on compilation
mark-drained #(.markDrained this)
f (fn [_]
(a/go
(let [result (a/alt!
ch ([x] (if (nil? x)
(do
(mark-drained)
default-val)
x))
(a/timeout timeout) timeout-val
:priority true)]
(d/success! d result))))]
(if (d/realized? d')
(f nil)
(d/on-realized d' f f))
(if blocking?
@d
d))))
(s/def-sink CoreAsyncSink
[ch ^AtomicReference last-put]
(description [this]
{:sink? true
:closed? (s/closed? this)
:type "core.async"})
(assert (not (nil? x)) "core.async channel cannot take `nil` as a message")
(if (nil? timeout)
(.put this x blocking?)
(assert (not (nil? x)) "core.async channel cannot take `nil` as a message"))
clojure.core.async.impl.channels.ManyToManyChannel
(to-sink [ch]
(->CoreAsyncSink
ch
(AtomicReference. (d/success-deferred true)))))
clojure.core.async.impl.channels.ManyToManyChannel
(to-source [ch]
(->CoreAsyncSource
ch
(AtomicReference. (d/success-deferred true)))))
hraberg/deuce
(ns deuce.emacs.fileio
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.string :as s]
[clojure.java.io :as io]
[deuce.emacs.buffer :as buffer]
[deuce.emacs.data :as data]
[deuce.emacs.eval :as eval]
[deuce.emacs.editfns :as editfns])
(:import [java.nio.file Files LinkOption
NoSuchFileException]
[deuce.emacs.data Buffer BufferText])
(:refer-clojure :exclude []))
(defvar write-region-inhibit-fsync nil
"*Non-nil means don't call fsync in `write-region'.
This variable affects calls to `write-region' as well as save commands.
A non-nil value may result in data loss!")
(defun unix-sync ()
"Tell Unix to finish all pending disk updates."
(interactive))
metosin/sieppari
(ns sieppari.async.core-async
(:require [sieppari.async :as sa]
[sieppari.util :refer [exception?]]
[clojure.core.async :as cca
#?@(:clj [:refer [go <! <!!]]
:cljs [:refer-macros [go]])]))
(extend-protocol sa/AsyncContext
#?(:clj clojure.core.async.impl.protocols.Channel
:cljs cljs.core.async.impl.channels/ManyToManyChannel)
(async? [_] true)
(continue [c f] (go (f (cca/<! c))))
(catch [c f] (go (let [c (cca/<! c)]
(if (exception? c) (f c) c))))
#?(:clj (await [c] (<!! c))))