File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -206,12 +206,19 @@ export class Callback {
206206 this . unsafe . close ( ) ;
207207 }
208208
209- // Static method for creating auto-managed callbacks
210- static createAutoManaged ( callback : PythonJSCallback ) : Callback {
211- const cb = new Callback ( callback ) ;
212- // Register the UnsafeCallback for automatic cleanup when the Callback is GC'd
213- callbackRegistry . register ( cb , cb . unsafe ) ;
214- return cb ;
209+ /**
210+ * Marks this Callback instance as "owned" by registering it with the
211+ * FinalizationRegistry for automatic cleanup when the Callback is garbage collected.
212+ *
213+ * This allows the underlying Deno.UnsafeCallback to be closed automatically
214+ * when the Callback object is no longer referenced, helping to prevent resource leaks.
215+ * This is useful if you don't want to call destroy manually.
216+ *
217+ * @returns {Callback } The current Callback instance.
218+ */
219+ get owned ( ) : Callback {
220+ callbackRegistry . register ( this , this . unsafe ) ;
221+ return this ;
215222 }
216223}
217224
@@ -608,7 +615,7 @@ export class PyObject {
608615 }
609616
610617 if ( typeof v === "function" ) {
611- return PyObject . from ( Callback . createAutoManaged ( v ) ) ;
618+ return PyObject . from ( new Callback ( v ) . owned ) ;
612619 }
613620 }
614621
You can’t perform that action at this time.
0 commit comments