File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ exclusive ownership of the object. A disposable object can become disposed
82
82
at any time.
83
83
84
84
The ` Symbol.dispose ` and ` Symbol.asyncDispose ` methods are called in both
85
- successful and exceptional exits from the scopes in which the using keyword
85
+ successful and exceptional exits from the scopes in which the ` using ` keyword
86
86
is used. This means that if an exception is thrown within the scope, the
87
87
disposal methods will still be called. However, when the disposal methods are
88
88
called they are not aware of the context. These methods will not receive any
@@ -144,7 +144,10 @@ A disposable object can be quite simple:
144
144
145
145
``` js
146
146
class MyResource {
147
+ #disposed = false ;
147
148
dispose () {
149
+ if (this .#disposed) return ;
150
+ this .#disposed = true ;
148
151
console .log (' Resource disposed' );
149
152
}
150
153
@@ -399,5 +402,3 @@ class MyDisposable {
399
402
Because of this, it is important to consider the possible relationships
400
403
between disposable objects. For example, if one disposable object holds a
401
404
reference to another disposable object the cleanup order may be important.
402
- If disposers are properly idempotent, however, this should not cause any
403
- issue, but it still requires careful consideration.
You can’t perform that action at this time.
0 commit comments