mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 18:50:42 -08:00
Updates to tuts and new with-sync-event
This commit is contained in:
parent
ec81e5fb2b
commit
18a5f8d78e
33 changed files with 157 additions and 104 deletions
|
|
@ -12,22 +12,26 @@
|
|||
(let ((x 0))
|
||||
(set-on-click hello-element
|
||||
(lambda (obj)
|
||||
(declare (ignore obj))
|
||||
(incf x)
|
||||
(dotimes (n x)
|
||||
(create-p body
|
||||
:content (format nil "Clicked ~A times." x))
|
||||
(sleep x)))))
|
||||
(declare (ignorable obj))
|
||||
;; Add to try non-parallel events:
|
||||
;; (with-sync-event (obj)
|
||||
(let ((y (incf x)))
|
||||
(dotimes (n y)
|
||||
(create-p body
|
||||
:content (format nil "Clicked ~A times." y))
|
||||
(sleep y)))))) ;)
|
||||
(run body)))
|
||||
|
||||
;;; Running this version of the last tutorial and clicking quickly on the (click me!)
|
||||
;;; will demonstrate an important aspect of CLOG, events can happen in _parallel_.
|
||||
;;; This means that appropriate precautions to thread protect data should be taken
|
||||
;;; and that events do not wait for previous event handlers to complete. One simple
|
||||
;;; way to avoid issues is to use the key :one-time t on the set-on-click or other
|
||||
;;; event, this will turn off the event immediately when the user clicks and can then
|
||||
;;; set the event again when done handling the event if want to again accept the event.
|
||||
;;; and that events do not wait for previous event handlers to complete. To change
|
||||
;;; this behavior just add at start of event WITH-SYNC-EVENT and then all events
|
||||
;;; will be serialized like in "traditional" GUIs to that event, events using
|
||||
;;; WITH-SYNC-EVENT will be on same queue of incoming events and syncronized.
|
||||
;;; But... notice what happens once syncing is on the next event doesn't hit until
|
||||
;;; SLEEP returns.
|
||||
(defun start-tutorial ()
|
||||
"Start turtorial."
|
||||
(initialize #'on-new-window)
|
||||
(initialize 'on-new-window)
|
||||
(open-browser))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue