We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b5cbfdb commit dd6d9b7Copy full SHA for dd6d9b7
examples/delay.janet
@@ -1,13 +1,11 @@
1
-(defn setup []
2
- (printf " -> running setup code, first time only."))
3
-
4
(def setup-once
5
- (delay
6
- (setup)
7
- "setup complete"))
+ (let [setup |(print "running setup")]
+ (delay
+ (setup)
+ "setup complete")))
+
+# first run will print "running setup" followed by "setup complete"
8
+(printf "first run: %s" (setup-once))
9
-repl:127:> (setup-once)
10
- -> running setup code, first time only.
11
-"setup complete"
12
-repl:128:> (setup-once)
13
+# after that, only prints cached value "setup complete"
+(printf "second run: %s" (setup-once))
0 commit comments