Created
April 19, 2021 13:09
-
-
Save saikyun/02859f7484a2f83b35e476a4d87e54a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def click-queue (ev/chan 4)) | |
(defn ev/check | |
[chan] | |
(when (pos? (ev/count chan)) | |
(ev/take chan))) | |
(defn ev/push | |
[chan v] | |
(when (ev/full chan) | |
(ev/take chan)) ## throw away old values | |
(ev/give chan v)) | |
(def dumb-queue @[]) | |
(defn take | |
[queue] | |
(array/pop queue)) | |
(defn push | |
[queue v] | |
(array/insert queue 0 v)) | |
(varfn draw-frame | |
[dt] | |
(when (mouse-button-pressed? 0) | |
(def pos (get-mouse-position)) | |
(ev/go (coro (ev/sleep 1) | |
(ev/push click-queue | |
(fn [] (print "delayed!") | |
(pp pos))) | |
(push dumb-queue | |
(fn [] (print "dumb delayed!") | |
(pp pos)))))) | |
(loop [f :iterate (take dumb-queue)] | |
(f)) | |
(loop [f :iterate (ev/check click-queue)] | |
(f))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment