Resource pool max waiters and destroy changes
Add the ability to specify the max number of waiters for a resource pool, this provides a more efficient way of avoiding waiters for a resource pool continually rising. This commit also improves the destroy behaviour.
This commit is contained in:
parent
8c0f04be4f
commit
4f0eafef0a
2 changed files with 333 additions and 62 deletions
|
@ -142,4 +142,48 @@
|
|||
20
|
||||
(iota 50)))))
|
||||
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(let ((resource-pool (make-resource-pool
|
||||
(lambda () #f)
|
||||
1
|
||||
#:default-max-waiters 1)))
|
||||
(call-with-resource-from-pool
|
||||
resource-pool
|
||||
(lambda (res)
|
||||
|
||||
;; 1st waiter
|
||||
(spawn-fiber
|
||||
(lambda ()
|
||||
(with-exception-handler
|
||||
(lambda (exn)
|
||||
(if (resource-pool-destroyed-error? exn)
|
||||
#t
|
||||
(raise-exception exn)))
|
||||
(lambda ()
|
||||
(call-with-resource-from-pool
|
||||
resource-pool
|
||||
(lambda (res)
|
||||
(error 'should-not-be-reached))))
|
||||
#:unwind? #t)))
|
||||
|
||||
(while (= 0
|
||||
(assq-ref
|
||||
(resource-pool-stats resource-pool)
|
||||
'waiters))
|
||||
(sleep 0))
|
||||
|
||||
(with-exception-handler
|
||||
(lambda (exn)
|
||||
(if (resource-pool-too-many-waiters-error? exn)
|
||||
#t
|
||||
(raise-exception exn)))
|
||||
(lambda ()
|
||||
;; 2nd waiter
|
||||
(call-with-resource-from-pool
|
||||
resource-pool
|
||||
(lambda (res)
|
||||
(error 'should-not-be-reached))))
|
||||
#:unwind? #t))))))
|
||||
|
||||
(display "resource-pool test finished successfully\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue