From 60d2623efc54eb38d8f4e087f39b32bee4e1aee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 10 Aug 2020 10:47:34 +0200 Subject: Add stream-timeslice-limit. --- module/srfi/srfi-41/util.scm | 15 +++++++++++++++ module/vcomponent/search.scm | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm index 472170d7..a6c6dc3d 100644 --- a/module/srfi/srfi-41/util.scm +++ b/module/srfi/srfi-41/util.scm @@ -102,6 +102,21 @@ (define*-public (stream-paginate stream optional: (page-size 10)) (stream-paginate% stream page-size)) + +(define (eager-stream-cons a b) + (stream-cons a b)) + +(use-modules (ice-9 sandbox) ) +(define (stream-timeslice-limit strm) + (call-with-time-limit + 0.1 + (lambda () (eager-stream-cons + (stream-car strm) + (stream-timeslice-limit (stream-cdr strm)))) + (lambda _ stream-null))) + +(export stream-timeslice-limit) + ;; Evaluates @var{body} in a context where most list fundamentals are ;; replaced by stream alternatives. ;; commented defifinitions are items which could be included, but for diff --git a/module/vcomponent/search.scm b/module/vcomponent/search.scm index 65e2630a..d240cbdc 100644 --- a/module/vcomponent/search.scm +++ b/module/vcomponent/search.scm @@ -63,7 +63,9 @@ ;; Creates a prepared query wrappend in a paginator. ;; (event → bool), (stream event) → (define-public (prepare-query query-proc event-set) - (make-paginator (stream-paginate (stream-filter query-proc event-set)))) + (make-paginator (stream-paginate + (stream-timeslice-limit + (stream-filter query-proc event-set))))) (define-record-type (make-paginator% query max-page true-max-page?) -- cgit v1.2.3