From 88feedbc01ab783117e81cea762fcca56de255fd Mon Sep 17 00:00:00 2001 From: Jailany M Date: Fri, 9 Aug 2024 16:02:23 +0530 Subject: [PATCH] feat: added forceFree function to free the resources and not delete the db --- src/clickstream.js | 25 +++++++++++++++++++++++++ test/clickstream.test.js | 1 + 2 files changed, 26 insertions(+) diff --git a/src/clickstream.js b/src/clickstream.js index 9d9c42a..ca17245 100644 --- a/src/clickstream.js +++ b/src/clickstream.js @@ -280,4 +280,29 @@ export default class Clickstream { ) } } + + /** + * frees up all the resource used by the Clickstream instance asynchronously and does not delete the database. + * + * clears the timeouts and intervals used. + * removes all the event listeners. + * flushes all the existing events in the system. + * + * It has no side effect on the working oh the SDK. + * calling .track() method again will re-create all the timeouts, interval and database for event tracking. + */ + async forceFree() { + try { + await this.#scheduler.free() + logger.info(logPrefix, "scheduler resources are released") + logger.info(logPrefix, "force cleanup is done. db is not deleted.") + } catch (error) { + return Promise.reject( + new ClickstreamError(error.message, { + name: errorNames.CLEANUP_ERROR, + code: errorCodes.CLEANUP_ERROR, + }) + ) + } + } } diff --git a/test/clickstream.test.js b/test/clickstream.test.js index ece4c2f..e0137e7 100644 --- a/test/clickstream.test.js +++ b/test/clickstream.test.js @@ -17,5 +17,6 @@ describe("clickstream", () => { expect(clckstrm.pause).toBeDefined() expect(clckstrm.resume).toBeDefined() expect(clckstrm.free).toBeDefined() + expect(clckstrm.forceFree).toBeDefined() }) })