dispose-each
parent
5bae9bf6ef
commit
f0f0cfb7c3
|
@ -1,6 +1,6 @@
|
||||||
USING: kernel math namespaces io tools.test sequences vectors
|
USING: kernel math namespaces io tools.test sequences vectors
|
||||||
continuations debugger parser memory arrays words
|
continuations debugger parser memory arrays words
|
||||||
kernel.private ;
|
kernel.private accessors ;
|
||||||
IN: continuations.tests
|
IN: continuations.tests
|
||||||
|
|
||||||
: (callcc1-test)
|
: (callcc1-test)
|
||||||
|
@ -100,3 +100,20 @@ SYMBOL: error-counter
|
||||||
[ 3 ] [ always-counter get ] unit-test
|
[ 3 ] [ always-counter get ] unit-test
|
||||||
[ 1 ] [ error-counter get ] unit-test
|
[ 1 ] [ error-counter get ] unit-test
|
||||||
] with-scope
|
] with-scope
|
||||||
|
|
||||||
|
TUPLE: dispose-error ;
|
||||||
|
|
||||||
|
M: dispose-error dispose 3 throw ;
|
||||||
|
|
||||||
|
TUPLE: dispose-dummy disposed? ;
|
||||||
|
|
||||||
|
M: dispose-dummy dispose t >>disposed? drop ;
|
||||||
|
|
||||||
|
T{ dispose-error } "a" set
|
||||||
|
T{ dispose-dummy } "b" set
|
||||||
|
|
||||||
|
[ f ] [ "b" get disposed?>> ] unit-test
|
||||||
|
|
||||||
|
[ { "a" "b" } [ get ] map dispose-each ] [ 3 = ] must-fail-with
|
||||||
|
|
||||||
|
[ t ] [ "b" get disposed?>> ] unit-test
|
||||||
|
|
|
@ -138,6 +138,11 @@ SYMBOL: thread-error-hook
|
||||||
|
|
||||||
GENERIC: dispose ( object -- )
|
GENERIC: dispose ( object -- )
|
||||||
|
|
||||||
|
: dispose-each ( seq -- )
|
||||||
|
[
|
||||||
|
[ [ dispose ] curry [ , ] recover ] each
|
||||||
|
] { } make dup empty? [ drop ] [ peek rethrow ] if ;
|
||||||
|
|
||||||
: with-disposal ( object quot -- )
|
: with-disposal ( object quot -- )
|
||||||
over [ dispose ] curry [ ] cleanup ; inline
|
over [ dispose ] curry [ ] cleanup ; inline
|
||||||
|
|
||||||
|
|
|
@ -26,14 +26,11 @@ M: destructor dispose
|
||||||
: add-always-destructor ( obj -- )
|
: add-always-destructor ( obj -- )
|
||||||
<destructor> always-destructors get push ;
|
<destructor> always-destructors get push ;
|
||||||
|
|
||||||
: dispose-each ( seq -- )
|
|
||||||
<reversed> [ dispose ] each ;
|
|
||||||
|
|
||||||
: do-always-destructors ( -- )
|
: do-always-destructors ( -- )
|
||||||
always-destructors get dispose-each ;
|
always-destructors get <reversed> dispose-each ;
|
||||||
|
|
||||||
: do-error-destructors ( -- )
|
: do-error-destructors ( -- )
|
||||||
error-destructors get dispose-each ;
|
error-destructors get <reversed> dispose-each ;
|
||||||
|
|
||||||
: with-destructors ( quot -- )
|
: with-destructors ( quot -- )
|
||||||
[
|
[
|
||||||
|
|
|
@ -47,7 +47,7 @@ PRIVATE>
|
||||||
] with-variable ; inline
|
] with-variable ; inline
|
||||||
|
|
||||||
: stop-server ( -- )
|
: stop-server ( -- )
|
||||||
servers get [ dispose ] each ;
|
servers get dispose-each ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue