Compare commits
3 commits
8100d36aa5
...
a8e07b738b
| Author | SHA1 | Date | |
|---|---|---|---|
| a8e07b738b | |||
| 05f7daf0e9 | |||
| 9c123bbfa9 |
2 changed files with 42 additions and 9 deletions
|
|
@ -391,7 +391,7 @@
|
||||||
(('list-resources reply)
|
(('list-resources reply)
|
||||||
(spawn-fiber
|
(spawn-fiber
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(put-message reply (list-copy resources))))
|
(put-message reply (vector->list resources))))
|
||||||
|
|
||||||
(loop available
|
(loop available
|
||||||
waiters))
|
waiters))
|
||||||
|
|
@ -967,7 +967,9 @@
|
||||||
(('list-resources reply)
|
(('list-resources reply)
|
||||||
(spawn-fiber
|
(spawn-fiber
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(put-message reply (list-copy resources))))
|
(put-message reply (hash-map->list
|
||||||
|
(lambda (_ value) value)
|
||||||
|
resources))))
|
||||||
|
|
||||||
(loop next-resource-id
|
(loop next-resource-id
|
||||||
available
|
available
|
||||||
|
|
@ -1115,13 +1117,14 @@
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let loop ()
|
(let loop ()
|
||||||
(put-message channel '(check-for-idle-resources))
|
(put-message channel '(check-for-idle-resources))
|
||||||
(when (choice-operation
|
(when (perform-operation
|
||||||
|
(choice-operation
|
||||||
(wrap-operation
|
(wrap-operation
|
||||||
(sleep-operation idle-seconds)
|
(sleep-operation idle-seconds)
|
||||||
(const #t))
|
(const #t))
|
||||||
(wrap-operation
|
(wrap-operation
|
||||||
(wait-operation destroy-condition)
|
(wait-operation destroy-condition)
|
||||||
(const #f)))
|
(const #f))))
|
||||||
(loop))))))
|
(loop))))))
|
||||||
|
|
||||||
(with-exception-handler
|
(with-exception-handler
|
||||||
|
|
|
||||||
|
|
@ -252,4 +252,34 @@
|
||||||
|
|
||||||
(destroy-resource-pool resource-pool))))
|
(destroy-resource-pool resource-pool))))
|
||||||
|
|
||||||
|
;; Test allocating resources to waiters and destroying resources
|
||||||
|
(run-fibers-for-tests
|
||||||
|
(lambda ()
|
||||||
|
(let ((resource-pool (make-resource-pool
|
||||||
|
(lambda ()
|
||||||
|
(sleep 1)
|
||||||
|
'res)
|
||||||
|
2
|
||||||
|
#:idle-seconds 1
|
||||||
|
#:add-resources-parallelism 10
|
||||||
|
#:destructor
|
||||||
|
(const #t))))
|
||||||
|
(fibers-for-each
|
||||||
|
(lambda _
|
||||||
|
(with-resource-from-pool resource-pool
|
||||||
|
res
|
||||||
|
res))
|
||||||
|
(iota 20))
|
||||||
|
|
||||||
|
(sleep 2)
|
||||||
|
|
||||||
|
(fibers-for-each
|
||||||
|
(lambda _
|
||||||
|
(with-resource-from-pool resource-pool
|
||||||
|
res
|
||||||
|
res))
|
||||||
|
(iota 20))
|
||||||
|
|
||||||
|
(destroy-resource-pool resource-pool))))
|
||||||
|
|
||||||
(display "resource-pool test finished successfully\n")
|
(display "resource-pool test finished successfully\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue