Skip to content

Commit

Permalink
Update to include lazy start in isLeader method
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmolyuk committed Apr 13, 2024
1 parent ba93142 commit 8b5ad5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ npm install mongo-leader
const client = await MongoClient.connect(url)

const leader = new Leader(client.db('test'))
await leader.start()
await leader.start() // Optional. If not called, a lazy start is initiated when isLeader is called for the first time.

setInterval(async () => {
const isLeader = await leader.isLeader()
Expand Down Expand Up @@ -57,7 +57,7 @@ This method triggers the election process. It carries out the required setup in

### isLeader()

This method is used to check if the current instance is the leader. It returns a Promise that resolves to a boolean value. `true` indicates that the current instance is the leader, and `false` indicates that it is not.
This method checks whether the current instance is the leader or not. It returns a Promise that resolves to a boolean value. If the returned value is `true`, it means the current instance is the leader. If the returned value is `false`, it means the current instance is not the leader. If the instance has not been initialized yet, a lazy start is performed.

### pause()

Expand Down
1 change: 0 additions & 1 deletion example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ async function connectAndStart() {
const client = await MongoClient.connect(url)

const leader = new Leader(client.db('test'))
await leader.start()

setInterval(async () => {
const isLeader = await leader.isLeader()
Expand Down

0 comments on commit 8b5ad5a

Please sign in to comment.