diff --git a/src/lease.ts b/src/lease.ts index be1e76e..22d2a91 100644 --- a/src/lease.ts +++ b/src/lease.ts @@ -151,6 +151,15 @@ export class Lease extends EventEmitter { }); } + /** + * releasePassively stops making heartbeats for the lease, and allows it + * to expire automatically when its TTL rolls around. Use `revoke()` to + * actively tell etcd to terminate the lease. + */ + public release() { + this.close(); + } + /** * Put returns a put builder that operates within the current lease. */ diff --git a/test/lease.test.ts b/test/lease.test.ts index 506821c..c76d6e9 100644 --- a/test/lease.test.ts +++ b/test/lease.test.ts @@ -30,7 +30,7 @@ describe('lease()', () => { it('throws if trying to use too short of a ttl, or an undefined ttl', () => { expect(() => client.lease(0)).to.throw(/must be at least 1 second/); - expect(() => ( client.lease)()).to.throw(/must be at least 1 second/); + expect(() => (client.lease)()).to.throw(/must be at least 1 second/); }); it('reports a loss and errors if the client is invalid', async () => { @@ -152,6 +152,13 @@ describe('lease()', () => { expect(res.TTL).to.equal('60'); }); + it('stops touching the lease if released passively', async () => { + const kaFired = watchEmission('keepaliveFired'); + lease.release(); + clock.tick(20000); + expect(kaFired.fired).to.be.false; + }); + it('tears down if the lease gets revoked', async () => { await client.leaseClient.leaseRevoke({ ID: await lease.grant() }); clock.tick(20000);