Skip to content

Commit

Permalink
chore: rebuild lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kobezzza committed Sep 19, 2024
1 parent 301122b commit c11c830
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 93 deletions.
8 changes: 4 additions & 4 deletions lib/core/async/core/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ export default class Async<CTX extends object = Async<any>> {
/**
* Cancels an asynchronous task (or a group of tasks) from the specified namespace
*
* @param task - the operation options or a reference to the task to be canceled
* @param params - the operation parameters or a reference to the task to be canceled
* @param [namespace] - the namespace from which the task or tasks should be canceled
*/
protected cancelTask(task: CanUndef<FullClearParams | any>, namespace?: Namespaces | PrimitiveNamespaces | PromiseNamespaces): this;
protected cancelTask(params: CanUndef<FullClearParams | any>, namespace?: Namespaces | PrimitiveNamespaces | PromiseNamespaces): this;
/**
* Marks an asynchronous task (or a group of tasks) within the specified namespace using the given marker
*
* @param marker
* @param task - the operation options or a reference to the task to be marked
* @param params - the operation parameters or a reference to the task to be marked
* @param [namespace] - the namespace from which the task or tasks should be marked
*/
protected markTask(marker: Marker, task: CanUndef<ClearProxyOptions | any>, namespace?: Namespaces | PrimitiveNamespaces | PromiseNamespaces): this;
protected markTask(marker: Marker, params: CanUndef<ClearProxyOptions | any>, namespace?: Namespaces | PrimitiveNamespaces | PromiseNamespaces): this;
/**
* Marks all asynchronous tasks within the specified namespace using the given marker
*
Expand Down
76 changes: 38 additions & 38 deletions lib/core/async/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Async {
links
} = cache,
{
links: commonLinks
links: globalLinks
} = commonCache.root;
const labelCache = label != null && labels != null ? labels[label] : null;
if (labelCache != null && params.join === true) {
Expand All @@ -84,7 +84,7 @@ class Async {
task = null;
if (!params.periodic || Object.isFunction(wrappedTask)) {
wrappedTask = (...args) => {
if (task == null) {
if (task == null || task.unregistered) {
return;
}
if (task.muted) {
Expand Down Expand Up @@ -190,13 +190,13 @@ class Async {
let taskRes;
switch (args.length) {
case 1:
taskRes = params.wrapper(args[0]);
taskRes = params.wrapper.call(null, args[0]);
break;
case 2:
taskRes = params.wrapper(args[0], args[1]);
taskRes = params.wrapper.call(null, args[0], args[1]);
break;
case 3:
taskRes = params.wrapper(args[0], args[1], args[2]);
taskRes = params.wrapper.call(null, args[0], args[1], args[2]);
break;
default:
taskRes = params.wrapper(...args);
Expand All @@ -214,33 +214,33 @@ class Async {
});
}
links.set(taskId, task);
if (links !== commonLinks) {
commonLinks.set(taskId, task);
if (links !== globalLinks) {
globalLinks.set(taskId, task);
}
if (label != null && labels != null) {
labels[label] = taskId;
}
return taskId;
}
cancelTask(task, namespace) {
task = task != null ? this.ids.get(task) ?? task : task;
cancelTask(params, namespace) {
params = params != null ? this.ids.get(params) ?? params : params;
let p;
if (namespace != null) {
if (task === undefined) {
if (params === undefined) {
return this.cancelTask({
namespace,
reason: 'all'
});
}
p = Object.isDictionary(task) ? {
...task,
p = Object.isDictionary(params) ? {
...params,
namespace
} : {
namespace,
id: task
id: params
};
} else {
p = task ?? {};
p = params ?? {};
}
const commonCache = this.getCache(p);
const {
Expand Down Expand Up @@ -290,23 +290,23 @@ class Async {
p.reason = 'id';
}
if (p.id != null) {
const link = links.get(p.id);
if (link != null) {
const skipZombie = link.group != null && p.reason === 'all' && _const2.isZombieGroup.test(link.group);
const task = links.get(p.id);
if (task != null) {
const skipZombie = task.group != null && p.reason === 'all' && _const2.isZombieGroup.test(task.group);
if (skipZombie) {
return this;
}
link.unregister();
task.unregister();
const ctx = {
...p,
link,
link: task,
type: 'clearAsync'
};
link.onClear.forEach(handler => {
task.onClear.forEach(handler => {
handler.call(this.ctx, ctx);
});
if (link.clear != null && !p.preventDefault) {
link.clear(link.id, ctx);
if (task.clear != null && !p.preventDefault) {
task.clear.call(null, task.id, ctx);
}
}
} else {
Expand All @@ -319,25 +319,25 @@ class Async {
}
return this;
}
markTask(marker, task, namespace) {
task = task != null ? this.ids.get(task) ?? task : task;
markTask(marker, params, namespace) {
params = params != null ? this.ids.get(params) ?? params : params;
let p;
if (namespace != null) {
if (task === undefined) {
if (params === undefined) {
return this.markTask(marker, {
namespace,
reason: 'all'
});
}
p = Object.isDictionary(task) ? {
...task,
p = Object.isDictionary(params) ? {
...params,
namespace
} : {
namespace,
id: task
id: params
};
} else {
p = task ?? {};
p = params ?? {};
}
const commonCache = this.getCache(p);
const {
Expand Down Expand Up @@ -384,21 +384,21 @@ class Async {
p.reason = 'id';
}
if (p.id != null) {
const link = links.get(p.id);
if (link) {
const skipZombie = link.group != null && p.reason === 'all' && _const2.isZombieGroup.test(link.group);
const task = links.get(p.id);
if (task) {
const skipZombie = task.group != null && p.reason === 'all' && _const2.isZombieGroup.test(task.group);
if (skipZombie) {
return this;
}
if (marker === '!paused') {
link.queue.forEach(fn => fn());
link.muted = false;
link.paused = false;
link.queue = [];
task.queue.forEach(fn => fn());
task.muted = false;
task.paused = false;
task.queue = [];
} else if (marker.startsWith('!')) {
link[marker.slice(1)] = false;
task[marker.slice(1)] = false;
} else {
link[marker] = true;
task[marker] = true;
}
}
} else {
Expand Down
8 changes: 6 additions & 2 deletions lib/core/async/core/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export declare type StrictClearOptionsId<ID = any> = Omit<ClearOptionsId<ID>, 'l
export interface ClearFn<CTX extends object = Async> extends Function {
(id: any, ctx: TaskCtx<CTX>): void;
}
export interface BoundedCb<CTX extends object = Async> extends Function {
export interface BoundFn<CTX extends object = Async> extends Function {
(this: CTX, ...args: any[]): void;
}
export interface Task<CTX extends object = Async> {
Expand All @@ -144,6 +144,10 @@ export interface Task<CTX extends object = Async> {
* The label associated with the task
*/
label?: Label;
/**
* True if the task is unregistered
*/
unregistered: boolean;
/**
* True if the task is paused
*/
Expand All @@ -159,7 +163,7 @@ export interface Task<CTX extends object = Async> {
/**
* A list of complete handlers: `[onFulfilled, onRejected][]`
*/
onComplete: Array<Array<BoundedCb<CTX>>>;
onComplete: Array<Array<BoundFn<CTX>>>;
/**
* A list of clear handlers
*/
Expand Down
6 changes: 4 additions & 2 deletions lib/core/async/core/task.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* https://github.com/V4Fire/Core/blob/master/LICENSE
*/
import type Async from '../../../core/async';
import type { Label, FullAsyncParams, LocalCache, GlobalCache, AsyncCb, BoundedCb, ClearFn, Task as AbstractTask } from '../../../core/async/interface';
import type { Label, FullAsyncParams, LocalCache, GlobalCache, AsyncCb, BoundFn, ClearFn, Task as AbstractTask } from '../../../core/async/interface';
export default class Task<CTX extends object = Async> implements AbstractTask<CTX> {
/** @inheritDoc */
readonly id: object;
Expand All @@ -19,13 +19,15 @@ export default class Task<CTX extends object = Async> implements AbstractTask<CT
/** @inheritDoc */
readonly label: CanUndef<Label>;
/** @inheritDoc */
unregistered: boolean;
/** @inheritDoc */
paused: boolean;
/** @inheritDoc */
muted: boolean;
/** @inheritDoc */
readonly queue: Function[];
/** @inheritDoc */
readonly onComplete: Array<Array<BoundedCb<CTX>>>;
readonly onComplete: Array<Array<BoundFn<CTX>>>;
/** @inheritDoc */
readonly onClear: Array<AsyncCb<CTX>>;
/** @inheritDoc */
Expand Down
13 changes: 6 additions & 7 deletions lib/core/async/core/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Task {
get name() {
return this.params.task.name;
}
unregistered = false;
paused = false;
muted = false;
queue = [];
Expand All @@ -27,16 +28,14 @@ class Task {
const {
id,
label,
cache: {
links,
labels
}
cache
} = this;
links.delete(id);
cache.links.delete(id);
this.globalCache.root.links.delete(id);
if (label != null && labels?.[label] != null) {
labels[label] = undefined;
if (label != null && cache.labels?.[label] != null) {
cache.labels[label] = undefined;
}
this.unregistered = true;
}
}
exports.default = Task;
6 changes: 1 addition & 5 deletions lib/core/async/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
* [[include:core/async/README.md]]
* @packageDocumentation
*/
import Super from '../../core/async/core/core';
import Wrappers from '../../core/async/wrappers';
export * from '../../core/async/const';
export * from '../../core/async/interface';
export * from '../../core/async/wrappers';
export * from '../../core/async/helpers';
interface Async<CTX extends object = Async<any>> extends Wrappers<CTX> {
export default class Async<CTX extends object = Async<any>> extends Wrappers<CTX> {
}
declare class Async<CTX extends object = Async<any>> extends Super<CTX> {
}
export default Async;
19 changes: 2 additions & 17 deletions lib/core/async/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
var _exportNames = {};
exports.default = void 0;
var _core = _interopRequireDefault(require("../../core/async/core/core"));
var _wrappers = _interopRequireWildcard(require("../../core/async/wrappers"));
Object.keys(_wrappers).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Expand Down Expand Up @@ -57,18 +55,5 @@ Object.keys(_helpers).forEach(function (key) {
});
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
class Async extends _core.default {}
var _default = Async;
exports.default = _default;
borrowAPI(_wrappers.default);
function borrowAPI(target) {
if (target !== _core.default) {
borrowAPI(Object.getPrototypeOf(target.prototype).constructor);
}
Object.entries(Object.getOwnPropertyDescriptors(target.prototype)).forEach(([name, desc]) => {
if (name === 'constructor') {
return;
}
Object.defineProperty(Async.prototype, name, desc);
});
}
class Async extends _wrappers.default {}
exports.default = Async;
4 changes: 2 additions & 2 deletions lib/core/async/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import type Async from '../../core/async';
import type { PromiseNamespaces } from '../../core/async/const';
import type { Task, TaskNamespaces, MarkReason, ClearReason, BoundedCb, ClearFn, AsyncProxyOptions, ClearProxyOptions } from '../../core/async/core/interface';
import type { Task, TaskNamespaces, MarkReason, ClearReason, BoundFn, ClearFn, AsyncProxyOptions, ClearProxyOptions } from '../../core/async/core/interface';
import type { AsyncWorkerOptions, AsyncPromiseOptions } from '../../core/async/proxy/interface';
import type { AsyncPromisifyOnceOptions } from '../../core/async/events/interface';
export * from '../../core/async/core/interface';
Expand Down Expand Up @@ -109,7 +109,7 @@ export declare type FullAsyncParams<CTX extends object = Async> = {
* }
* ```
*/
wrapper?: BoundedCb<CTX>;
wrapper?: BoundFn<CTX>;
/**
* Additional arguments to the task wrapper
*
Expand Down
14 changes: 7 additions & 7 deletions lib/core/async/proxy/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class Async extends _proxy.default {
this.ids.set(wrappedPromise, wrappedResolve);
return wrappedPromise;
function promiseConstructor(resolve, reject) {
let canceled = false,
proxyReject = null;
let canceled = false;
let wrappedReject = null;
wrappedResolve = that.proxy(resolve, {
...p,
clear: () => {
that.promiseDestructor(p.destructor, promise);
if (proxyReject != null) {
if (wrappedReject != null) {
that.clearProxy({
id: proxyReject,
id: wrappedReject,
namespace: p.namespace
});
}
Expand All @@ -76,7 +76,7 @@ class Async extends _proxy.default {
const handlers = Array.toArray(opts?.onMutedResolve);
if (handlers.length > 0) {
handlers.forEach(handler => {
handler.call(ctx, wrappedResolve, proxyReject);
handler.call(ctx, wrappedResolve, wrappedReject);
});
} else {
reject({
Expand All @@ -92,7 +92,7 @@ class Async extends _proxy.default {
if (Object.isFunction(promise)) {
promise = promise();
}
proxyReject = that.proxy(err => {
wrappedReject = that.proxy(err => {
if (canceled || p.namespace == null) {
return;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ class Async extends _proxy.default {
namespace: p.namespace,
group: p.group
});
return promise.then(wrappedResolve, proxyReject);
promise.then(wrappedResolve, wrappedReject);
}
}
}
Expand Down
Loading

0 comments on commit c11c830

Please sign in to comment.