! Copyright (C) 2007, 2010 Doug Coleman, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs continuations init kernel make
-namespaces sequences sets ;
-FROM: namespaces => set ;
+USING: accessors assocs continuations kernel namespaces
+sequences sets ;
IN: destructors
SYMBOL: disposables
disposables get adjoin ;
: unregister-disposable ( obj -- )
- disposables get 2dup in? [ delete ] [ drop already-unregistered ] if ;
+ dup disposables get ?delete [ drop ] [ already-unregistered ] if ;
PRIVATE>
[ last rethrow ] unless-empty ;
: with-disposal ( object quot -- )
- over [ dispose ] curry [ ] cleanup ; inline
+ over [ dispose ] curry finally ; inline
<PRIVATE
dup error-destructors get push ; inline
: with-destructors ( quot -- )
- [
- V{ } clone always-destructors set
- V{ } clone error-destructors set
+ H{ } clone
+ V{ } clone always-destructors pick set-at
+ V{ } clone error-destructors pick set-at [
[ do-always-destructors ]
[ do-error-destructors ]
cleanup
- ] with-scope ; inline
+ ] with-variables ; inline
-[
+STARTUP-HOOK: [
HS{ } clone disposables set-global
V{ } clone always-destructors set-global
V{ } clone error-destructors set-global
-] "destructors" add-startup-hook
+]
-[
+SHUTDOWN-HOOK: [
do-always-destructors
do-error-destructors
-] "destructors" add-shutdown-hook
+]