diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-10 13:28:13 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-08-10 13:28:13 +0200 |
commit | d8c3f29f788f6b508818d78d72975cb251ec9ee8 (patch) | |
tree | 58d18c261c1f43251de55384a08eb4e3c57d0db2 /module/srfi/srfi-41 | |
parent | Remove old limiter on execute-query. (diff) | |
download | calp-d8c3f29f788f6b508818d78d72975cb251ec9ee8.tar.gz calp-d8c3f29f788f6b508818d78d72975cb251ec9ee8.tar.xz |
Got new timeslice limiter to work, document.
Diffstat (limited to '')
-rw-r--r-- | module/srfi/srfi-41/util.scm | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/module/srfi/srfi-41/util.scm b/module/srfi/srfi-41/util.scm index a6c6dc3d..51671985 100644 --- a/module/srfi/srfi-41/util.scm +++ b/module/srfi/srfi-41/util.scm @@ -1,8 +1,10 @@ (define-module (srfi srfi-41 util) #:use-module (srfi srfi-1) #:use-module (srfi srfi-41) + #:use-module ((ice-9 sandbox) :select (call-with-time-limit)) #:use-module (util) ; let*, find-min - #:export (stream-car+cdr interleave-streams with-streams)) + #:export (stream-car+cdr interleave-streams with-streams + stream-timeslice-limit)) (define (stream-car+cdr stream) (values (stream-car stream) @@ -103,20 +105,21 @@ (stream-paginate% stream page-size)) +;; stream cons, but eval arguments beforehand. (define (eager-stream-cons a b) (stream-cons a b)) -(use-modules (ice-9 sandbox) ) -(define (stream-timeslice-limit strm) +;; Wrap a stream in time limits. Each element has at most @var{timeslice} +;; seconds to produce a value, otherwise the stream ends. Useful for finding the +;; "final" element matching a predicate in an infinite stream. +(define-stream (stream-timeslice-limit strm timeslice) (call-with-time-limit - 0.1 + timeslice (lambda () (eager-stream-cons (stream-car strm) - (stream-timeslice-limit (stream-cdr strm)))) + (stream-timeslice-limit (stream-cdr strm) timeslice))) (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 |