Back
delay (clj)
(source)macro
(delay & body)
Takes a body of expressions and yields a Delay object that will
invoke the body only the first time it is forced (with force or deref/@), and
will cache the result and return it on all subsequent force
calls. See also - realized?
Examples
clojure/core.typed
(ns ^:skip-wiki clojure.core.typed.ann.clojure
"Type annotations for the base Clojure distribution."
(:require [#?(:clj clojure.core.typed
:cljs cljs.core.typed)
:refer [defalias] :as t]))
(defalias
^{:doc "A Clojure delay (see clojure.core/{delay,force})."
:forms '[(Delay t)]}
t/Delay
(t/TFn [[x :variance :covariant]]
(clojure.lang.Delay x)))
hraberg/deuce
(ns deuce.emacs.process
(:use [deuce.emacs-lisp :only (defun defvar) :as el])
(:require [clojure.core :as c]
[clojure.java.shell :as sh])
(:refer-clojure :exclude []))
(defvar process-adaptive-read-buffering nil
"If non-nil, improve receive buffering by delaying after short reads.
On some systems, when Emacs reads the output from a subprocess, the output data
is read in very small blocks, potentially resulting in very poor performance.
This behavior can be remedied to some extent by setting this variable to a
non-nil value, as it will automatically delay reading from such processes, to
allow them to produce more output before Emacs tries to read it.
If the value is t, the delay is reset after each write to the process; any other
non-nil value means that the delay is not reset on write.
The variable takes effect when `start-process' is called.")
hraberg/deuce
(ns deuce.emacs
(:require [clojure.core :as c]
[deuce.emacs-lisp :as el]
[deuce.emacs-lisp.globals :as globals])
(:refer-clojure :only [])
(:use [deuce.emacs-lisp :only [and apply-partially catch cond condition-case defconst define-compiler-macro defmacro
defun defvar function if interactive lambda let let* or prog1 prog2 progn quote
save-current-buffer save-excursion save-restriction setq setq-default
unwind-protect while throw]]
[deuce.emacs.alloc]
[deuce.emacs.buffer]
[deuce.emacs.bytecode]
[deuce.emacs.callint]
[deuce.emacs.callproc]
[deuce.emacs.casefiddle]
[deuce.emacs.casetab]
[deuce.emacs.category]
[deuce.emacs.ccl]
[deuce.emacs.character]
[deuce.emacs.charset]
[deuce.emacs.chartab]
[deuce.emacs.cmds]
[deuce.emacs.coding]
[deuce.emacs.composite]
[deuce.emacs.data]
[deuce.emacs.dired]
[deuce.emacs.dispnew]
[deuce.emacs.doc]
[deuce.emacs.editfns]
[deuce.emacs.emacs]
[deuce.emacs.eval]
[deuce.emacs.fileio]
[deuce.emacs.filelock]
[deuce.emacs.floatfns]
[deuce.emacs.fns]
[deuce.emacs.font]
[deuce.emacs.frame]
[deuce.emacs.indent]
[deuce.emacs.insdel]
[deuce.emacs.keyboard]
[deuce.emacs.keymap]
[deuce.emacs.lread]
[deuce.emacs.macros]
[deuce.emacs.marker]
[deuce.emacs.menu]
[deuce.emacs.minibuf]
[deuce.emacs.print]
[deuce.emacs.process]
[deuce.emacs.search]
[deuce.emacs.syntax]
[deuce.emacs.term]
[deuce.emacs.terminal]
[deuce.emacs.textprop]
[deuce.emacs.undo]
[deuce.emacs.window]
[deuce.emacs.xdisp]
[deuce.emacs.xfaces]
[deuce.emacs.xml]))
;; Hack for a predicate in cl.el, this is defined in emacs-lisp/bytecomp.el, which we're not using
(defun byte-compile-file-form (form))
;; ;; AOT cl.el gets confused by this alias
(defalias 'cl-block-wrapper 'identity)
(defmacro declare (&rest _specs) nil)
;; with-no-warnings in byte-run.el needs this
(defun last (list &optional n))
;; subr defines a simpler dolist, which custom uses, which gets redefined by cl-macs.
;; During AOT custom loads the latter dolist definition, requiring 'block' - not yet defined.
;; cl cannot be loaded first, as it depends on help-fns, which depend on custom.
(defmacro block (name &rest body) (cons 'progn body))
;; Hack as delayed-eval doesn't (like some other things) work properly inside let-bindings.
;; Needs to be fixed properly, but let's see if we can get through the boot with this hack.
;; cl-setf-simple-store-p is used in cl-macs/cl-setf-do-modify, delayed-eval call refers to earlier binding 'method'.
(defun cl-setf-simple-store-p (sym form))
;; Same issue in regexp-opt/regexp-opt. Calls this fn with earlier binding 'sorted-strings'
(defun regexp-opt-group (strings &optional paren lax))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
(t/defalias
^{:doc "A Clojure delay (see clojure.core/{delay,force})."
:forms '[(Delay x)]}
t/Delay
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.Delay x)
:cljs (cljs.core/Delay x))))
cc/delay? (t/Pred (t/Delay t/Any))
skuttleman/defacto
(ns defacto.resources.core-test
#?(:cljs (:require-macros defacto.resources.core-test))
(:require
[clojure.core.async :as async]
[clojure.test :refer [deftest is testing]]
[defacto.core :as defacto]
[defacto.resources.core :as res]
[defacto.test.utils :as tu]))
(testing "when delaying a resource"
(reset! calls [])
(defacto/dispatch! store [::res/delay! 100 [::res/submit! [::resource 123] {:some :params}]])
(testing "and when the delay has not expired"
(async/<! (async/timeout 50))
(testing "does not submit the resource"
(is (empty? @calls))))
(testing "and when the delay has expired"
(async/<! (async/timeout 51))
(testing "submits the resource"
(is (= @calls [[::request-fn {:some :params}]])))))