-
Notifications
You must be signed in to change notification settings - Fork 3
/
protocols.clj
33 lines (27 loc) · 1.43 KB
/
protocols.clj
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
(ns imminent.protocols
(:refer-clojure :exclude [map filter await]))
(defprotocol IReturn
(success? [this])
(failure? [this])
(map-failure [this f]
"applies the supplied function to the internal value only if it is a Failure type"))
(defprotocol IFuture
(on-success [fut f]
"applies f to the result of this future iff it completes successfully")
(on-failure [fut f]
"applies f to the result of this future iff it completes with a failure")
(on-complete [fut f]
"applies f to a value of type 'IResult' once this future completes")
(filter [fut pred]
"Applies pred to the value of this Future. The new Future will contain a value of type success if (pre value) is true. It will contain a Failure wrapping a NoSuchElementException otherwise")
(zip [fut other]
"Zips this future with 'other'. Resturns a new Future containing a two-element vector representing the result of each Future.")
(completed? [fut]
"Returns true when this future has been completed with a value or an exception. False otherwise"))
(defprotocol IAwaitable
(await
[awaitable]
[awaitable ms] "Blocks until the awaitable reference is done. Optionally awaits for up to 'ms' milliseconds, throwing a TimeoutException once time is up."))
(defprotocol IPromise
(complete [promise value] "Completes this promise with the given value")
(->future [promise] "Returns a Future backed by this promise"))