@v1nt1248/3nclient-lib 0.1.13 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
+ export * from './processes';
1
2
  export * from './textarea-max-rows';
2
- export * from './common.utils';
3
- export * from './ui.utils';
3
+ export * from './common';
4
+ export * from './ui';
4
5
  export { SQLiteOn3NStorage } from './sqlite-on-3nstorage';
5
6
  export type { BindParams, Database, QueryExecResult } from './sqlite-on-3nstorage';
@@ -0,0 +1,136 @@
1
+ export declare function sleep(millis: number): Promise<void>;
2
+ /**
3
+ * Standard Promise has no finally() method, when all respected libraries do.
4
+ * Inside of an async function one may use try-finally clause. But, when we
5
+ * work with raw promises, we need a compact finalization routine. And this is
6
+ * it for synchronous completion.
7
+ * @param promise
8
+ * @param fin is a synchronous function that performs necessary
9
+ * finalization/cleanup. Use finalizeAsync, when finalization is asynchronous.
10
+ * @return a finalized promise
11
+ */
12
+ export declare function finalize<T>(promise: Promise<T>, fin: () => void): Promise<T>;
13
+ /**
14
+ * Standard Promise has no finally() method, when all respected libraries do.
15
+ * Inside of an async function one may use try-finally clause. But, when we
16
+ * work with raw promises, we need a compact finalization routine. And this is
17
+ * it for an asynchronous completion.
18
+ * @param promise
19
+ * @param fin is an asynchronous function that performs necessary
20
+ * finalization/cleanup. Use finalize, when finalization is synchronous
21
+ * (is not returning promise).
22
+ * @return a finalized promise
23
+ */
24
+ export declare function finalizeAsync<T>(promise: Promise<T>, fin: () => Promise<void>): Promise<T>;
25
+ /**
26
+ * This represents a function that will create a promise, potentially starting
27
+ * some background process, only when it is called. Such wrap of code is needed
28
+ * for scheduling, as very often any start of an action must be postponed till
29
+ * later time. Scheduler needs a not-yet-started activity, as scheduler has
30
+ * control action's start.
31
+ */
32
+ export type Action<T> = () => Promise<T>;
33
+ /**
34
+ * This is a container of processes, labeled by some ids. It allows to track if
35
+ * there is a process already in progress with a given id. And, it allows to
36
+ * chain process, when needed.
37
+ *
38
+ * Common use of such class is to reuse getting of some expensive resource(s).
39
+ */
40
+ export declare class NamedProcs {
41
+ private promises;
42
+ constructor();
43
+ /**
44
+ * @param id is a string key of a process
45
+ * @return a promise of a process' completion, or undefined, if process with
46
+ * given id is unknown.
47
+ */
48
+ getP<T>(id: string): Promise<T> | undefined;
49
+ private insertPromise;
50
+ /**
51
+ * This method will add a promise of an already started process.
52
+ * @param id is a string key of a process
53
+ * @param promise of an already started process
54
+ * @return a promise of a process' completion.
55
+ */
56
+ addStarted<T>(id: string, promise: Promise<T>): Promise<T>;
57
+ /**
58
+ * This method will start a given action only, if a process with a given id
59
+ * is not running.
60
+ * @param id is a string key of a process
61
+ * @param action is a function that starts some process
62
+ * @return a promise of a process' completion.
63
+ */
64
+ start<T>(id: string, action: Action<T>): Promise<T>;
65
+ /**
66
+ * This method will chain a given action to an already running process, or,
67
+ * if identified process is not running, this will start given action under
68
+ * a given id.
69
+ * @param id is a string key of a process
70
+ * @param action is a function that starts some process
71
+ * @return a promise of a process' completion.
72
+ */
73
+ startOrChain<T>(id: string, action: Action<T>): Promise<T>;
74
+ }
75
+ /**
76
+ * This is a container of process. It allows to track if a process is already
77
+ * in progress. It also allows to chain process, when needed.
78
+ *
79
+ * Common use of such class is to reuse getting of some expensive resource, or
80
+ * do ning something as an exclusive process.
81
+ */
82
+ export declare class SingleProc {
83
+ private promise;
84
+ constructor();
85
+ private insertPromise;
86
+ getP<T>(): Promise<T> | undefined;
87
+ addStarted<T>(promise: Promise<T>): Promise<T>;
88
+ start<T>(action: Action<T>): Promise<T>;
89
+ startOrChain<T>(action: Action<T>): Promise<T>;
90
+ }
91
+ export declare class DeduppedRunner<T> {
92
+ private readonly action;
93
+ private proc;
94
+ private waiting;
95
+ constructor(action: Action<T>);
96
+ trigger(): Promise<T>;
97
+ private startAction;
98
+ }
99
+ /**
100
+ * This wraps given function/method into syncing wrap.
101
+ */
102
+ export declare function makeSyncedFunc<T extends Function>(syncProc: SingleProc, thisArg: any, func: T): T;
103
+ /**
104
+ * This is a cycling process, that ensures single execution.
105
+ * It cycles while given "while" predicate returns true. When predicate returns
106
+ * false, process goes to idle. Pushing this process into action is done via
107
+ * startIfIdle() method.
108
+ */
109
+ export declare class SingleCyclicProc {
110
+ private cycleWhile;
111
+ private action;
112
+ private proc;
113
+ /**
114
+ * @param cycleWhile is a "while" predicate. When it returns true, process
115
+ * continues to cycle, and when it returns false, process goes to idle.
116
+ * @param action is an async cycle body to run at each iteration.
117
+ */
118
+ constructor(cycleWhile: () => boolean, action: () => Promise<void>);
119
+ /**
120
+ * This starts process, if it is idle.
121
+ */
122
+ startIfIdle(): void;
123
+ private cycleOrIdle;
124
+ isRunning(): boolean;
125
+ /**
126
+ * This makes process unusable and unstartable. Waiting on a return promise,
127
+ * awaits the completion of the last iteration this process is in (if any).
128
+ */
129
+ close(): Promise<void>;
130
+ }
131
+ export interface Deferred<T> {
132
+ promise: Promise<T>;
133
+ resolve: (result: T | PromiseLike<T>) => void;
134
+ reject: (err: any) => void;
135
+ }
136
+ export declare function defer<T>(): Deferred<T>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.1.13",
5
+ "version": "0.1.14",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
File without changes
File without changes