Skip to content

Instantly share code, notes, and snippets.

@leonoel
leonoel / deps.edn
Created December 30, 2022 10:30
Missionary implementation of kafka consumer with backpressure and manual offset commits
{: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"}}}
@leonoel
leonoel / prepl.clj
Last active February 21, 2024 16:47
Example of clojure prepl usage with missionary
(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.
@leonoel
leonoel / animation.clj
Created October 8, 2023 13:16
animation in missionary
(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
@leonoel
leonoel / promise.clj
Created October 23, 2023 07:17
missionary promise interop with abort
(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#)