/* IBM Confidential OCO Source Materials IBM Cognos Products: rs (C) Copyright IBM Corp. 2018 The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office. */ define([], function() { // In IE, there is no guarantee that calling clearTimeout will actually stop a setTimeout from firing. These wrappers provide an extra level // of control to ensure that a setTimeout will not fire once the timer has been cleared. // To keep things simple, we use the same implementation for all browsers since the overhead of the wrapper is minimal. var f_timeoutHandler = function(v_fn, v_oTimeoutHandle) { if (v_oTimeoutHandle.m_iTimeoutId !== null) { v_oTimeoutHandle.m_iTimeoutId = null; v_fn(); } }; var U_ClearableTimeout = {}; U_ClearableTimeout.F_Create = function(v_fn, v_iTimeout) { var v_oTimeoutHandle = {}; v_oTimeoutHandle.m_iTimeoutId = setTimeout(f_timeoutHandler.bind(this, v_fn, v_oTimeoutHandle), v_iTimeout); return v_oTimeoutHandle; }; U_ClearableTimeout.F_Clear = function(v_oTimeoutHandle) { if (v_oTimeoutHandle.m_iTimeoutId) { /* * The order of the next lines is significant. It appears that under some circumstances, calling clearTimeout will actually * run a previous setTimeout in the same thread. Clearing our active timeout record ensures that it will get ignored. */ var v_iTimeoutId = v_oTimeoutHandle.m_iTimeoutId; v_oTimeoutHandle.m_iTimeoutId = null; clearTimeout(v_iTimeoutId); } }; return U_ClearableTimeout; });