Basic loopback resource.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns foo.baz
  (:api dunaj)
  (:require [dunaj.resource.loopback :refer [loopback]]
            [dunaj.concurrent.thread :refer [sleep]]))

;; non-blocking example
(with-io-scope
  (let [l (acquire! (loopback nil :non-blocking? true))]
    (write! l [1 2 3 4])
    (let [x (reduce #(println! "got" %2) nil (read! l))]
      (println! (postponed? x))
      (write! l [5 6 7 8])
      (unsafe-advance! x))
    (sleep 1000)))
;; got 1
;; got 2
;; got 3
;; got 4
;; true
;; got 5
;; got 6
;; got 7
;; got 8
;;=> nil

;; blocking-example
(with-io-scope
  (let [l (acquire! (loopback nil))]
    (write! l [1 2 3 4])
    (thread (with-io-scope (dored [x (read! l)] (println! "got" x))))
    (sleep 1000)))
;; got 1
;; got 2
;; got 3
;; got 4
;;=> nil

loopback

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (loopback)

  • (loopback size-hint & {:as opts})

Type signatures:
  • () → LoopbackResource

  • ((Maybe Integer+) ⨯ Any) → LoopbackResource

Returns a thread safe loopback resource factory, which will return back the written data.

See also: loopback-factory

loopback-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type IAcquirableFactory

Loopback resource factory. Thread safe.

See also: loopback