@@ -54,16 +54,20 @@ export namespace Event {
54
54
}
55
55
56
56
/**
57
- * Given an event, returns another event which debounces calls and defers the listeners to a
58
- * later task via a shared `setTimeout`. The event is converted into a signal (`Event<void>`) to
59
- * avoid additional object creation as a result of merging events and to try prevent race
60
- * conditions that could arise when using related deferred and non-deferred events.
57
+ * Given an event, returns another event which debounces calls and defers the listeners to a later task via a shared
58
+ * `setTimeout`. The event is converted into a signal (`Event<void>`) to avoid additional object creation as a
59
+ * result of merging events and to try prevent race conditions that could arise when using related deferred and
60
+ * non-deferred events.
61
61
*
62
- * This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not
63
- * block critical work (eg. latency of keypress to text rendered).
62
+ * This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not block critical work
63
+ * (eg. latency of keypress to text rendered).
64
+ *
65
+ * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
66
+ * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
67
+ * returned event causes this utility to leak a listener on the original event.
64
68
*/
65
- export function defer ( event : Event < unknown > ) : Event < void > {
66
- return debounce < unknown , void > ( event , ( ) => void 0 , 0 ) ;
69
+ export function defer ( event : Event < unknown > , disposable ?: DisposableStore ) : Event < void > {
70
+ return debounce < unknown , void > ( event , ( ) => void 0 , 0 , undefined , undefined , disposable ) ;
67
71
}
68
72
69
73
/**
0 commit comments