@cordisjs/timer
Advanced tools
Comparing version 0.1.0 to 0.1.1
134
lib/index.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Logger = void 0; | ||
const cordis_1 = require("cordis"); | ||
const cosmokit_1 = require("cosmokit"); | ||
const reggol_1 = __importDefault(require("reggol")); | ||
exports.Logger = reggol_1.default; | ||
class TimerService extends cordis_1.Service { | ||
constructor(ctx) { | ||
super(ctx, 'timer', true); | ||
(0, cosmokit_1.defineProperty)(this, cordis_1.Context.current, ctx); | ||
} | ||
createTimerDispose(timer) { | ||
const dispose = () => { | ||
clearTimeout(timer); | ||
if (!this[cordis_1.Context.current].scope) | ||
return; | ||
return (0, cosmokit_1.remove)(this[cordis_1.Context.current].scope.disposables, dispose); | ||
}; | ||
this[cordis_1.Context.current].scope.disposables.push(dispose); | ||
return dispose; | ||
} | ||
setTimeout(callback, ms, ...args) { | ||
const dispose = this.createTimerDispose(setTimeout(() => { | ||
dispose(); | ||
callback(); | ||
}, ms, ...args)); | ||
return dispose; | ||
} | ||
setInterval(callback, ms, ...args) { | ||
return this.createTimerDispose(setInterval(callback, ms, ...args)); | ||
} | ||
sleep(ms) { | ||
return new Promise((resolve, reject) => { | ||
const dispose1 = this.setTimeout(() => { | ||
dispose1(); | ||
dispose2(); | ||
resolve(); | ||
}, ms); | ||
const dispose2 = this[cordis_1.Context.current].on('dispose', () => { | ||
dispose1(); | ||
dispose2(); | ||
reject(new Error('Context disposed')); | ||
}); | ||
}); | ||
} | ||
} | ||
exports.default = TimerService; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// cordis/std/packages/timer/src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
Logger: () => import_reggol.default, | ||
default: () => src_default | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var import_cordis = require("cordis"); | ||
var import_cosmokit = require("cosmokit"); | ||
var import_reggol = __toESM(require("reggol")); | ||
var _TimerService = class _TimerService extends import_cordis.Service { | ||
constructor(ctx) { | ||
super(ctx, "timer", true); | ||
(0, import_cosmokit.defineProperty)(this, import_cordis.Context.current, ctx); | ||
} | ||
createTimerDispose(timer) { | ||
const dispose = /* @__PURE__ */ __name(() => { | ||
clearTimeout(timer); | ||
if (!this[import_cordis.Context.current].scope) | ||
return; | ||
return (0, import_cosmokit.remove)(this[import_cordis.Context.current].scope.disposables, dispose); | ||
}, "dispose"); | ||
this[import_cordis.Context.current].scope.disposables.push(dispose); | ||
return dispose; | ||
} | ||
setTimeout(callback, ms, ...args) { | ||
const dispose = this.createTimerDispose(setTimeout(() => { | ||
dispose(); | ||
callback(); | ||
}, ms, ...args)); | ||
return dispose; | ||
} | ||
setInterval(callback, ms, ...args) { | ||
return this.createTimerDispose(setInterval(callback, ms, ...args)); | ||
} | ||
sleep(ms) { | ||
return new Promise((resolve, reject) => { | ||
const dispose1 = this.setTimeout(() => { | ||
dispose1(); | ||
dispose2(); | ||
resolve(); | ||
}, ms); | ||
const dispose2 = this[import_cordis.Context.current].on("dispose", () => { | ||
dispose1(); | ||
dispose2(); | ||
reject(new Error("Context disposed")); | ||
}); | ||
}); | ||
} | ||
}; | ||
__name(_TimerService, "TimerService"); | ||
var TimerService = _TimerService; | ||
var src_default = TimerService; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Logger | ||
}); |
{ | ||
"name": "@cordisjs/timer", | ||
"description": "Timer plugin for cordis", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "module": "lib/index.mjs", |
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
7704
6
206