This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns promise) | |
(defmacro with-abort " | |
Returns a task evaluating `body` with symbol `a` bound to a fresh `AbortSignal` that is aborted when the task is | |
cancelled. The task completes with the result of returned promise. | |
" [a & body] | |
`(fn [s# f#] | |
(let [c# (js/AbortController.) | |
~a (.-signal c#)] | |
(try (.then (do ~@body) s# f#) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns animation | |
(:refer-clojure :exclude [cycle]) | |
(:require [missionary.core :as m])) | |
;; A signal giving the current time in milliseconds. | |
;; On the browser, you may want to use an RAF-based clock instead. | |
(def <time | |
(->> (m/ap | |
(loop [] | |
(m/amb nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns prepl | |
(:require [clojure.core.server :as s] | |
[missionary.core :as m]) | |
(:import (java.io PipedReader PipedWriter) | |
(java.util.concurrent Executors))) | |
(defn remote " | |
Returns a function taking a `java.io.PipedWriter` and returning a flow connecting to a remote prepl on given `host` and | |
`port`, sending the content of the pipe to the remote peer and emitting received evaluation results. The pipe is closed | |
on flow cancellation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:deps {org.clojure/clojure {:mvn/version "1.11.1"} | |
org.apache.kafka/kafka-clients {:mvn/version "3.3.1"} | |
missionary/missionary {:mvn/version "b.26"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ^{:doc " | |
Performance measurements for various generator implementations, cloroutine v10 https://github.com/leonoel/cloroutine | |
Based on https://clojureverse.org/t/how-to-transform-nested-map-into-flat-sequence-of-path-value-pairs/8801/22 | |
"} cloroutine-perf | |
(:require [cloroutine.core :refer [cr]])) | |
(def ^:dynamic *tail*) | |
(defn gen-seq-dv [gen] | |
(lazy-seq (binding [*tail* (gen-seq-dv gen)] (gen)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Experiment - parallel processing using missionary primitives. | |
;; Inspired by Rx's parallel 'rails' : | |
;; http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/parallel/ParallelFlowable.html | |
;; https://dzone.com/articles/rxjava-idiomatic-concurrency-flatmap-vs-parallel | |
(ns parallel-processing | |
(:require [missionary.core :as m])) | |
(defn map-task [f >x] | |
(m/ap (m/? (f (m/?> >x))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns complex-business-process-example-missionary | |
"A stupid example of a more complex business process to implement as a flowchart." | |
(:require [missionary.core :as m]) | |
(:import missionary.Cancelled)) | |
;;;; Config | |
(def config | |
"When set to :test will trigger the not-boosted branch which won't write to db. | |
When set to :prod will trigger the boosted branch which will try to write to the db." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; missionary implementation of SICP's [amb](http://sarabander.github.io/sicp/html/4_002e3.xhtml#g_t4_002e3) | |
(ns amb | |
(:refer-clojure :exclude [require eval]) | |
(:require [missionary.core :as m])) | |
(deftype FlowIterator [^:unsynchronized-mutable iterator | |
^:unsynchronized-mutable pending?] | |
clojure.lang.IFn | |
(invoke [this] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; missionary solution to petrol pump example by Stephen Blackheath and Anthony Jones, ISBN 978-1633430105 | |
;; huanhulan's demo : [live](https://huanhulan.github.io/petrol_pump), [code](https://github.com/huanhulan/petrol_pump) | |
(ns pump | |
(:refer-clojure :exclude [first]) | |
(:require [missionary.core :as m]) | |
(:import missionary.Cancelled)) | |
(defn rising | |
"A transducer that outputs `nil` when the input switches from logical false to logical true." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns goto) | |
(defmacro tagbody [& forms] | |
(let [start (gensym)] | |
(loop [binds [] | |
point start | |
forms forms] | |
(let [[body [jump & forms]] (split-with (complement symbol?) forms) | |
binds (conj binds `(~point [] ~@body ~jump))] | |
(if jump |
NewerOlder