diff --git a/CHANGELOG.md b/CHANGELOG.md index f6d9872a65..56ac9ce069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🐞 Bug fixes - Fix updating terrain tiles on feature state changes ([#6231](https://github.com/maplibre/maplibre-gl-js/issues/6231)) (by [pstaszek](https://github.com/pstaszek)) - _...Add new stuff here..._ +- fix error during task execution blocking any further task execution ([#7031](https://github.com/maplibre/maplibre-gl-js/pull/7031)) ## 5.17.0 diff --git a/src/util/task_queue.test.ts b/src/util/task_queue.test.ts index 5ac20982f0..5f44c3dfc4 100644 --- a/src/util/task_queue.test.ts +++ b/src/util/task_queue.test.ts @@ -112,4 +112,15 @@ describe('TaskQueue', () => { q.run(); expect(after).not.toHaveBeenCalled(); }); + + test('Resets _currentlyRunning when a task throws an error', () => { + const q = new TaskQueue(); + q.add(() => { throw new Error('Task error'); }); + expect(() => q.run()).toThrow('Task error'); + // Should be able to run again - _currentlyRunning should be false + const afterError = vi.fn(); + q.add(afterError); + q.run(); + expect(afterError).toHaveBeenCalledTimes(1); + }); }); diff --git a/src/util/task_queue.ts b/src/util/task_queue.ts index 1718bee66d..d8dcbf00ef 100644 --- a/src/util/task_queue.ts +++ b/src/util/task_queue.ts @@ -45,14 +45,16 @@ export class TaskQueue { // on the next run, not the current run. this._queue = []; - for (const task of queue) { - if (task.cancelled) continue; - task.callback(timeStamp); - if (this._cleared) break; + try { + for (const task of queue) { + if (task.cancelled) continue; + task.callback(timeStamp); + if (this._cleared) break; + } + } finally { + this._cleared = false; + this._currentlyRunning = false; } - - this._cleared = false; - this._currentlyRunning = false; } clear() {