detritus-utils
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -34,3 +34,3 @@ import * as Timers from './timers'; | ||
expire?: number; | ||
interval: Timers.Interval; | ||
interval?: Timers.Interval; | ||
intervalTime: number; | ||
@@ -37,0 +37,0 @@ limit: number; |
@@ -100,3 +100,2 @@ "use strict"; | ||
this.cache = new Map(); | ||
this.interval = new Timers.Interval(); | ||
this.intervalTime = 5000; | ||
@@ -120,3 +119,3 @@ this.limit = Infinity; | ||
expire: { configurable: true, writable: false }, | ||
interval: { enumerable: false }, | ||
interval: { enumerable: false, writeable: true }, | ||
intervalTime: { configurable: true, enumerable: false, writable: false }, | ||
@@ -136,3 +135,3 @@ limit: { enumerable: false }, | ||
get shouldStartInterval() { | ||
return !this.interval.hasStarted && !!this.intervalTime; | ||
return !!this.intervalTime && (!this.interval || !!this.interval.hasStarted); | ||
} | ||
@@ -165,2 +164,5 @@ setExpire(value) { | ||
if (this.intervalTime && this.expire) { | ||
if (!this.interval) { | ||
this.interval = new Timers.Interval(); | ||
} | ||
this.interval.start(this.intervalTime, () => { | ||
@@ -187,3 +189,6 @@ const expire = this.expire; | ||
stopInterval() { | ||
this.interval.stop(); | ||
if (this.interval) { | ||
this.interval.stop(); | ||
} | ||
this.interval = undefined; | ||
} | ||
@@ -190,0 +195,0 @@ get size() { |
@@ -5,5 +5,5 @@ "use strict"; | ||
URL: 'https://github.com/detritusjs/utils', | ||
VERSION: '0.2.0', | ||
VERSION: '0.2.1', | ||
}); | ||
exports.DISCORD_SNOWFLAKE_EPOCH = 1420070400000; | ||
exports.DISCORD_TOKEN_EPOCH = 1293840000000; |
@@ -11,3 +11,11 @@ /// <reference types="node" /> | ||
hasEventListener(name: string): boolean; | ||
subscribe(event: string | symbol, listener: (...args: any[]) => void): EventSubscription; | ||
} | ||
export declare class EventSubscription { | ||
listener: ((...args: any[]) => void) | null; | ||
name: string | symbol; | ||
spewer: EventSpewer | null; | ||
constructor(spewer: EventSpewer, name: string | symbol, listener: (...args: any[]) => void); | ||
remove(): void; | ||
} | ||
export {}; |
@@ -21,3 +21,23 @@ "use strict"; | ||
} | ||
subscribe(event, listener) { | ||
const subscription = new EventSubscription(this, event, listener); | ||
this.on(event, listener); | ||
return subscription; | ||
} | ||
} | ||
exports.EventSpewer = EventSpewer; | ||
class EventSubscription { | ||
constructor(spewer, name, listener) { | ||
this.name = name; | ||
this.listener = listener; | ||
this.spewer = spewer; | ||
} | ||
remove() { | ||
if (this.listener && this.spewer) { | ||
this.spewer.removeListener(this.name, this.listener); | ||
} | ||
this.listener = null; | ||
this.spewer = null; | ||
} | ||
} | ||
exports.EventSubscription = EventSubscription; |
{ | ||
"name": "detritus-utils", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Detritus Utils", | ||
@@ -12,3 +12,3 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/node": "^12.7.12" | ||
"@types/node": "^12.11.7" | ||
}, | ||
@@ -15,0 +15,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24681
835