Skip to content

Commit 3c3fc27

Browse files
committed
page: add call-with-page-change-evt
1 parent c2c2126 commit 3c3fc27

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

marionette-doc/scribblings/marionette.scrbl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ separately.
389389
@defproc[(page-change-evt [page page?]) (evt/c void?)]{
390390
Returns a synchronizable event that becomes ready for synchronization
391391
when the page contents have changed (for example, when the user
392-
navigates to another page). The synchronization result of a page
393-
change event is @racket[void]. Once a page change event has
394-
synchronized, a new event must be created in order to observe further
395-
page changes.
392+
navigates to another page). The synchronization result of a
393+
@deftech{page change event} is @racket[void]. Once a page change
394+
event has synchronized, a new event must be created in order to
395+
observe further page changes.
396396

397397
When selected for synchronization, a page change event spawns a
398398
background thread to poll the page for changes. The thread will run
@@ -412,6 +412,16 @@ separately.
412412
@history[#:added "1.5"]
413413
}
414414

415+
@defproc[(call-with-page-change-evt [p page?] [proc (-> page-change-evt? any)]) any]{
416+
Calls @racket[proc] with a @tech{page change event} for @racket[p],
417+
abandoning it when @racket[proc] returns or whenever control escapes
418+
the dynamic extent of the call. Whenever control re-enters the dynamic
419+
extent of a call to @racket[call-with-page-change-evt], a new page
420+
change event is created.
421+
422+
@history[#:added "1.6"]
423+
}
424+
415425
@subsection[#:tag "reference/element"]{Element}
416426

417427
@deftech{Elements} represent individual elements on a specific page.

marionette-lib/info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#lang info
22

33
(define license 'BSD-3-Clause)
4-
(define version "1.5")
4+
(define version "1.6")
55
(define collection "marionette")
66
(define deps
77
'("base"

marionette-lib/page.rkt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@
314314
(provide
315315
page-change-evt?
316316
page-change-evt
317-
abandon-page-change-evt)
317+
abandon-page-change-evt
318+
call-with-page-change-evt)
318319

319320
(struct page-change-evt (p token [abandoned? #:mutable])
320321
#:name -page-change-evt
@@ -347,6 +348,16 @@
347348
(set-page-change-evt-abandoned?! e #t)
348349
(sync/enable-break e))
349350

351+
(define (call-with-page-change-evt p proc)
352+
(define e #f)
353+
(dynamic-wind
354+
(lambda ()
355+
(set! e (page-change-evt p)))
356+
(lambda ()
357+
(proc e))
358+
(lambda ()
359+
(abandon-page-change-evt e))))
360+
350361
;; element ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
351362

352363
(provide

0 commit comments

Comments
 (0)