var processingEvent:boolean = false; if (window.DeviceOrientationEvent) { window.addEventListener('deviceorientation', (data): void=> { if (Math.abs(lastAlpha - data.alpha) < 2) { return; } if (processingEvent) { return; }; processingEvent = true; lastAlpha = data.alpha; if (data.absolute === true && data.alpha !== null) { this.deviceOrientation = Math.round(360 - data.alpha); console.log(this.deviceOrientation.toString()); this.updateArrows(); } processingEvent = false; }, false); } else { alert('DeviceOrienation not supported'); }I noticed the event listener could be called again before the routine has finished (the event is raised extremely frequently) so added the 'processing' flag to prevent re-entrancy. It works fine - but it also appeared to work without the check so I'm wondering whether there is any really benefit in it.