Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added forceFree to free the resources and not delete the db #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/clickstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
)
}
}
}
1 change: 1 addition & 0 deletions test/clickstream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ describe("clickstream", () => {
expect(clckstrm.pause).toBeDefined()
expect(clckstrm.resume).toBeDefined()
expect(clckstrm.free).toBeDefined()
expect(clckstrm.forceFree).toBeDefined()
})
})