diff --git a/ui/imports/utils/Backpressure/Backpressure.qml b/ui/imports/utils/Backpressure/Backpressure.qml index 3ad3ae637f9..0f5aaabee8b 100644 --- a/ui/imports/utils/Backpressure/Backpressure.qml +++ b/ui/imports/utils/Backpressure/Backpressure.qml @@ -21,13 +21,13 @@ Item { owner = backpressure; } - owner.Component.destruction.connect(cleanup); + owner.Component.onDestruction.connect(cleanup); var obj = Qt.createQmlObject('import QtQuick 2.0; Timer {running: false; repeat: false; interval: ' + timeout + '}', backpressure, "setTimeout"); obj.triggered.connect(function() { callback(); obj.destroy(); - owner.Component.destruction.disconnect(cleanup); + owner.Component.onDestruction.disconnect(cleanup); delete _timers[tid]; }); obj.running = true; @@ -62,6 +62,32 @@ Item { } } + // Same as `oneInTime` while also handling any queued calls + function oneInTimeQueued(owner, duration, callback) { + var pending = false; + var queued = false; + var timerId = null; + + var proxy = function() { + if (pending) { + queued = true; + return; + } + pending = true; + queued = false; + var args = arguments; + callback.apply(null, args); + timerId = setTimeout(owner, duration , function() { + pending = false; + if (queued) { + proxy(owner, duration, callback); + } + }, duration); + } + + return proxy + } + function promisedOneInTime(owner, callback) { var q = priv.loadPromiseLib(); var promise = null;