goscript 0.0.26 → 0.0.29
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.
- package/README.md +4 -4
- package/cmd/goscript/cmd_compile.go +0 -3
- package/cmd/goscript/deps.go +11 -0
- package/compiler/analysis.go +298 -55
- package/compiler/assignment.go +2 -2
- package/compiler/builtin_test.go +1 -1
- package/compiler/compiler.go +200 -68
- package/compiler/compiler_test.go +17 -24
- package/compiler/composite-lit.go +32 -8
- package/compiler/decl.go +6 -6
- package/compiler/expr-call.go +170 -15
- package/compiler/expr-selector.go +100 -0
- package/compiler/expr.go +1 -1
- package/compiler/protobuf.go +557 -0
- package/compiler/spec-struct.go +4 -0
- package/compiler/spec-value.go +89 -10
- package/compiler/spec.go +254 -1
- package/compiler/stmt-assign.go +35 -0
- package/compiler/type-assert.go +87 -0
- package/compiler/type.go +4 -1
- package/dist/gs/builtin/builtin.d.ts +20 -1
- package/dist/gs/builtin/builtin.js +95 -4
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +1 -1
- package/dist/gs/builtin/slice.js +21 -2
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +5 -6
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/internal/oserror/errors.d.ts +6 -0
- package/dist/gs/internal/oserror/errors.js +7 -0
- package/dist/gs/internal/oserror/errors.js.map +1 -0
- package/dist/gs/internal/oserror/index.d.ts +1 -0
- package/dist/gs/internal/oserror/index.js +2 -0
- package/dist/gs/internal/oserror/index.js.map +1 -0
- package/dist/gs/io/fs/format.d.ts +3 -0
- package/dist/gs/io/fs/format.js +56 -0
- package/dist/gs/io/fs/format.js.map +1 -0
- package/dist/gs/io/fs/fs.d.ts +79 -0
- package/dist/gs/io/fs/fs.js +200 -0
- package/dist/gs/io/fs/fs.js.map +1 -0
- package/dist/gs/io/fs/glob.d.ts +10 -0
- package/dist/gs/io/fs/glob.js +141 -0
- package/dist/gs/io/fs/glob.js.map +1 -0
- package/dist/gs/io/fs/index.d.ts +8 -0
- package/dist/gs/io/fs/index.js +9 -0
- package/dist/gs/io/fs/index.js.map +1 -0
- package/dist/gs/io/fs/readdir.d.ts +7 -0
- package/dist/gs/io/fs/readdir.js +152 -0
- package/dist/gs/io/fs/readdir.js.map +1 -0
- package/dist/gs/io/fs/readfile.d.ts +6 -0
- package/dist/gs/io/fs/readfile.js +118 -0
- package/dist/gs/io/fs/readfile.js.map +1 -0
- package/dist/gs/io/fs/stat.d.ts +6 -0
- package/dist/gs/io/fs/stat.js +87 -0
- package/dist/gs/io/fs/stat.js.map +1 -0
- package/dist/gs/io/fs/sub.d.ts +6 -0
- package/dist/gs/io/fs/sub.js +172 -0
- package/dist/gs/io/fs/sub.js.map +1 -0
- package/dist/gs/io/fs/walk.d.ts +7 -0
- package/dist/gs/io/fs/walk.js +76 -0
- package/dist/gs/io/fs/walk.js.map +1 -0
- package/dist/gs/io/index.d.ts +1 -0
- package/dist/gs/io/index.js +2 -0
- package/dist/gs/io/index.js.map +1 -0
- package/dist/gs/io/io.d.ts +107 -0
- package/dist/gs/io/io.js +385 -0
- package/dist/gs/io/io.js.map +1 -0
- package/dist/gs/path/index.d.ts +2 -0
- package/dist/gs/path/index.js +3 -0
- package/dist/gs/path/index.js.map +1 -0
- package/dist/gs/path/match.d.ts +6 -0
- package/dist/gs/path/match.js +281 -0
- package/dist/gs/path/match.js.map +1 -0
- package/dist/gs/path/path.d.ts +7 -0
- package/dist/gs/path/path.js +256 -0
- package/dist/gs/path/path.js.map +1 -0
- package/dist/gs/strings/builder.d.ts +18 -0
- package/dist/gs/strings/builder.js +205 -0
- package/dist/gs/strings/builder.js.map +1 -0
- package/dist/gs/strings/clone.d.ts +1 -0
- package/dist/gs/strings/clone.js +16 -0
- package/dist/gs/strings/clone.js.map +1 -0
- package/dist/gs/strings/compare.d.ts +1 -0
- package/dist/gs/strings/compare.js +14 -0
- package/dist/gs/strings/compare.js.map +1 -0
- package/dist/gs/strings/index.d.ts +2 -0
- package/dist/gs/strings/index.js +3 -0
- package/dist/gs/strings/index.js.map +1 -0
- package/dist/gs/strings/iter.d.ts +8 -0
- package/dist/gs/strings/iter.js +160 -0
- package/dist/gs/strings/iter.js.map +1 -0
- package/dist/gs/strings/reader.d.ts +34 -0
- package/dist/gs/strings/reader.js +418 -0
- package/dist/gs/strings/reader.js.map +1 -0
- package/dist/gs/strings/replace.d.ts +106 -0
- package/dist/gs/strings/replace.js +1136 -0
- package/dist/gs/strings/replace.js.map +1 -0
- package/dist/gs/strings/search.d.ts +24 -0
- package/dist/gs/strings/search.js +169 -0
- package/dist/gs/strings/search.js.map +1 -0
- package/dist/gs/strings/strings.d.ts +47 -0
- package/dist/gs/strings/strings.js +418 -0
- package/dist/gs/strings/strings.js.map +1 -0
- package/dist/gs/stringslite/index.d.ts +1 -0
- package/dist/gs/stringslite/index.js +2 -0
- package/dist/gs/stringslite/index.js.map +1 -0
- package/dist/gs/stringslite/strings.d.ts +11 -0
- package/dist/gs/stringslite/strings.js +67 -0
- package/dist/gs/stringslite/strings.js.map +1 -0
- package/dist/gs/sync/index.d.ts +1 -0
- package/dist/gs/sync/index.js +2 -0
- package/dist/gs/sync/index.js.map +1 -0
- package/dist/gs/sync/sync.d.ts +79 -0
- package/dist/gs/sync/sync.js +392 -0
- package/dist/gs/sync/sync.js.map +1 -0
- package/dist/gs/time/time.d.ts +11 -2
- package/dist/gs/time/time.js +337 -12
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/index.d.ts +1 -0
- package/dist/gs/unicode/index.js +2 -0
- package/dist/gs/unicode/index.js.map +1 -0
- package/dist/gs/unicode/unicode.d.ts +105 -0
- package/dist/gs/unicode/unicode.js +332 -0
- package/dist/gs/unicode/unicode.js.map +1 -0
- package/dist/gs/unicode/utf8/index.d.ts +1 -0
- package/dist/gs/unicode/utf8/index.js +3 -0
- package/dist/gs/unicode/utf8/index.js.map +1 -0
- package/dist/gs/unicode/utf8/utf8.d.ts +20 -0
- package/dist/gs/unicode/utf8/utf8.js +196 -0
- package/dist/gs/unicode/utf8/utf8.js.map +1 -0
- package/dist/gs/unsafe/index.d.ts +1 -0
- package/dist/gs/unsafe/index.js +2 -0
- package/dist/gs/unsafe/index.js.map +1 -0
- package/dist/gs/unsafe/unsafe.d.ts +11 -0
- package/dist/gs/unsafe/unsafe.js +44 -0
- package/dist/gs/unsafe/unsafe.js.map +1 -0
- package/go.mod +2 -1
- package/go.sum +6 -2
- package/gs/README.md +6 -0
- package/gs/builtin/builtin.ts +171 -0
- package/gs/builtin/channel.ts +683 -0
- package/gs/builtin/defer.ts +58 -0
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/io.ts +22 -0
- package/gs/builtin/map.ts +50 -0
- package/gs/builtin/slice.ts +1030 -0
- package/gs/builtin/type.ts +1106 -0
- package/gs/builtin/varRef.ts +25 -0
- package/gs/cmp/godoc.txt +8 -0
- package/gs/cmp/index.ts +29 -0
- package/gs/context/context.ts +401 -0
- package/gs/context/godoc.txt +69 -0
- package/gs/context/index.ts +1 -0
- package/gs/errors/errors.ts +223 -0
- package/gs/errors/godoc.txt +63 -0
- package/gs/errors/index.ts +1 -0
- package/gs/internal/goarch/godoc.txt +39 -0
- package/gs/internal/goarch/index.ts +18 -0
- package/gs/internal/oserror/errors.ts +14 -0
- package/gs/internal/oserror/index.ts +1 -0
- package/gs/io/fs/format.ts +65 -0
- package/gs/io/fs/fs.ts +359 -0
- package/gs/io/fs/glob.ts +167 -0
- package/gs/io/fs/godoc.txt +35 -0
- package/gs/io/fs/index.ts +8 -0
- package/gs/io/fs/readdir.ts +126 -0
- package/gs/io/fs/readfile.ts +77 -0
- package/gs/io/fs/stat.ts +38 -0
- package/gs/io/fs/sub.ts +208 -0
- package/gs/io/fs/walk.ts +89 -0
- package/gs/io/godoc.txt +61 -0
- package/gs/io/index.ts +1 -0
- package/gs/io/io.go +75 -0
- package/gs/io/io.ts +546 -0
- package/gs/iter/godoc.txt +203 -0
- package/gs/iter/index.ts +1 -0
- package/gs/iter/iter.ts +117 -0
- package/gs/math/bits/index.ts +356 -0
- package/gs/math/godoc.txt +76 -0
- package/gs/path/index.ts +2 -0
- package/gs/path/match.ts +307 -0
- package/gs/path/path.ts +301 -0
- package/gs/runtime/godoc.txt +331 -0
- package/gs/runtime/index.ts +1 -0
- package/gs/runtime/runtime.ts +178 -0
- package/gs/slices/godoc.txt +44 -0
- package/gs/slices/index.ts +1 -0
- package/gs/slices/slices.ts +22 -0
- package/gs/strings/builder.test.ts +121 -0
- package/gs/strings/builder.ts +223 -0
- package/gs/strings/clone.test.ts +43 -0
- package/gs/strings/clone.ts +17 -0
- package/gs/strings/compare.test.ts +84 -0
- package/gs/strings/compare.ts +13 -0
- package/gs/strings/godoc.txt +66 -0
- package/gs/strings/index.ts +2 -0
- package/gs/strings/iter.test.ts +343 -0
- package/gs/strings/iter.ts +171 -0
- package/gs/strings/reader.test.ts +242 -0
- package/gs/strings/reader.ts +451 -0
- package/gs/strings/replace.test.ts +181 -0
- package/gs/strings/replace.ts +1310 -0
- package/gs/strings/search.test.ts +214 -0
- package/gs/strings/search.ts +213 -0
- package/gs/strings/strings.test.ts +477 -0
- package/gs/strings/strings.ts +510 -0
- package/gs/stringslite/godoc.txt +17 -0
- package/gs/stringslite/index.ts +1 -0
- package/gs/stringslite/strings.ts +82 -0
- package/gs/sync/godoc.txt +21 -0
- package/gs/sync/index.ts +1 -0
- package/gs/sync/sync.go +64 -0
- package/gs/sync/sync.ts +449 -0
- package/gs/time/godoc.txt +116 -0
- package/gs/time/index.ts +1 -0
- package/gs/time/time.ts +585 -0
- package/gs/unicode/godoc.txt +52 -0
- package/gs/unicode/index.ts +1 -0
- package/gs/unicode/unicode.go +38 -0
- package/gs/unicode/unicode.ts +418 -0
- package/gs/unicode/utf8/godoc.txt +22 -0
- package/gs/unicode/utf8/index.ts +2 -0
- package/gs/unicode/utf8/utf8.ts +227 -0
- package/gs/unsafe/godoc.txt +19 -0
- package/gs/unsafe/index.ts +1 -0
- package/gs/unsafe/unsafe.test.ts +68 -0
- package/gs/unsafe/unsafe.ts +77 -0
- package/package.json +4 -3
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
// Package sync provides basic synchronization primitives such as mutual exclusion
|
|
2
|
+
// locks. Other than the Once and WaitGroup types, most are intended for use by
|
|
3
|
+
// low-level library routines. Higher-level synchronization is better done via
|
|
4
|
+
// channels and communication.
|
|
5
|
+
// Mutex is a mutual exclusion lock
|
|
6
|
+
export class Mutex {
|
|
7
|
+
_locked = false;
|
|
8
|
+
_waitQueue = [];
|
|
9
|
+
constructor(init) {
|
|
10
|
+
// Mutex has no public fields to initialize
|
|
11
|
+
}
|
|
12
|
+
// Lock locks m
|
|
13
|
+
// If the lock is already in use, the calling goroutine blocks until the mutex is available
|
|
14
|
+
async Lock() {
|
|
15
|
+
if (!this._locked) {
|
|
16
|
+
this._locked = true;
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// In a real implementation, this would block the goroutine
|
|
20
|
+
// Use Promise to simulate blocking behavior like channels
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
this._waitQueue.push(resolve);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
// TryLock tries to lock m and reports whether it succeeded
|
|
26
|
+
TryLock() {
|
|
27
|
+
if (!this._locked) {
|
|
28
|
+
this._locked = true;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Unlock unlocks m
|
|
34
|
+
Unlock() {
|
|
35
|
+
if (!this._locked) {
|
|
36
|
+
throw new Error('sync: unlock of unlocked mutex');
|
|
37
|
+
}
|
|
38
|
+
this._locked = false;
|
|
39
|
+
// Wake up the next waiting goroutine
|
|
40
|
+
if (this._waitQueue.length > 0) {
|
|
41
|
+
const next = this._waitQueue.shift();
|
|
42
|
+
this._locked = true;
|
|
43
|
+
// Use queueMicrotask to simulate goroutine scheduling
|
|
44
|
+
queueMicrotask(() => next());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// clone returns a copy of this Mutex instance
|
|
48
|
+
clone() {
|
|
49
|
+
return new Mutex();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// RWMutex is a reader/writer mutual exclusion lock
|
|
53
|
+
export class RWMutex {
|
|
54
|
+
_readers = 0;
|
|
55
|
+
_writer = false;
|
|
56
|
+
_readerWaitQueue = [];
|
|
57
|
+
_writerWaitQueue = [];
|
|
58
|
+
constructor(init) {
|
|
59
|
+
// RWMutex has no public fields to initialize
|
|
60
|
+
}
|
|
61
|
+
// Lock locks rw for writing
|
|
62
|
+
async Lock() {
|
|
63
|
+
if (!this._writer && this._readers === 0) {
|
|
64
|
+
this._writer = true;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
this._writerWaitQueue.push(resolve);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// TryLock tries to lock rw for writing and reports whether it succeeded
|
|
72
|
+
TryLock() {
|
|
73
|
+
if (!this._writer && this._readers === 0) {
|
|
74
|
+
this._writer = true;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
// Unlock unlocks rw for writing
|
|
80
|
+
Unlock() {
|
|
81
|
+
if (!this._writer) {
|
|
82
|
+
throw new Error('sync: unlock of unlocked RWMutex');
|
|
83
|
+
}
|
|
84
|
+
this._writer = false;
|
|
85
|
+
this._wakeUpWaiters();
|
|
86
|
+
}
|
|
87
|
+
// RLock locks rw for reading
|
|
88
|
+
async RLock() {
|
|
89
|
+
if (!this._writer) {
|
|
90
|
+
this._readers++;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
this._readerWaitQueue.push(() => {
|
|
95
|
+
this._readers++;
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// TryRLock tries to lock rw for reading and reports whether it succeeded
|
|
101
|
+
TryRLock() {
|
|
102
|
+
if (!this._writer) {
|
|
103
|
+
this._readers++;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
// RUnlock undoes a single RLock call
|
|
109
|
+
RUnlock() {
|
|
110
|
+
if (this._readers === 0) {
|
|
111
|
+
throw new Error('sync: RUnlock of unlocked RWMutex');
|
|
112
|
+
}
|
|
113
|
+
this._readers--;
|
|
114
|
+
if (this._readers === 0) {
|
|
115
|
+
this._wakeUpWaiters();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
_wakeUpWaiters() {
|
|
119
|
+
// Prioritize writers
|
|
120
|
+
if (this._writerWaitQueue.length > 0 && this._readers === 0) {
|
|
121
|
+
const next = this._writerWaitQueue.shift();
|
|
122
|
+
this._writer = true;
|
|
123
|
+
queueMicrotask(() => next());
|
|
124
|
+
}
|
|
125
|
+
else if (this._readerWaitQueue.length > 0 && !this._writer) {
|
|
126
|
+
// Wake up all waiting readers
|
|
127
|
+
const readers = this._readerWaitQueue.splice(0);
|
|
128
|
+
queueMicrotask(() => {
|
|
129
|
+
readers.forEach((reader) => reader());
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// clone returns a copy of this RWMutex instance
|
|
134
|
+
clone() {
|
|
135
|
+
return new RWMutex();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// WaitGroup waits for a collection of goroutines to finish
|
|
139
|
+
export class WaitGroup {
|
|
140
|
+
_counter = 0;
|
|
141
|
+
_waiters = [];
|
|
142
|
+
constructor(init) {
|
|
143
|
+
// WaitGroup has no public fields to initialize
|
|
144
|
+
}
|
|
145
|
+
// Add adds delta, which may be negative, to the WaitGroup counter
|
|
146
|
+
Add(delta) {
|
|
147
|
+
this._counter += delta;
|
|
148
|
+
if (this._counter < 0) {
|
|
149
|
+
throw new Error('sync: negative WaitGroup counter');
|
|
150
|
+
}
|
|
151
|
+
if (this._counter === 0) {
|
|
152
|
+
// Wake up all waiters
|
|
153
|
+
const waiters = this._waiters.splice(0);
|
|
154
|
+
queueMicrotask(() => {
|
|
155
|
+
waiters.forEach((waiter) => waiter());
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Done decrements the WaitGroup counter by one
|
|
160
|
+
Done() {
|
|
161
|
+
this.Add(-1);
|
|
162
|
+
}
|
|
163
|
+
// Wait blocks until the WaitGroup counter is zero
|
|
164
|
+
async Wait() {
|
|
165
|
+
if (this._counter === 0) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return new Promise((resolve) => {
|
|
169
|
+
this._waiters.push(resolve);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
// clone returns a copy of this WaitGroup instance
|
|
173
|
+
clone() {
|
|
174
|
+
return new WaitGroup();
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Once is an object that will perform exactly one action
|
|
178
|
+
export class Once {
|
|
179
|
+
_done = false;
|
|
180
|
+
_m = new Mutex();
|
|
181
|
+
constructor(init) {
|
|
182
|
+
// Once has no public fields to initialize
|
|
183
|
+
}
|
|
184
|
+
// Do calls the function f if and only if Do is being called for the first time for this instance of Once
|
|
185
|
+
async Do(f) {
|
|
186
|
+
if (this._done) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
await this._m.Lock();
|
|
190
|
+
try {
|
|
191
|
+
if (!this._done) {
|
|
192
|
+
f();
|
|
193
|
+
this._done = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
this._m.Unlock();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// clone returns a copy of this Once instance
|
|
201
|
+
clone() {
|
|
202
|
+
return new Once();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Cond implements a condition variable, a rendezvous point for goroutines waiting for or announcing the occurrence of an event
|
|
206
|
+
export class Cond {
|
|
207
|
+
_l;
|
|
208
|
+
_waiters = [];
|
|
209
|
+
constructor(l) {
|
|
210
|
+
this._l = l;
|
|
211
|
+
}
|
|
212
|
+
// Broadcast wakes all goroutines waiting on c
|
|
213
|
+
Broadcast() {
|
|
214
|
+
const waiters = this._waiters.splice(0);
|
|
215
|
+
queueMicrotask(() => {
|
|
216
|
+
waiters.forEach((waiter) => waiter());
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// Signal wakes one goroutine waiting on c, if there is any
|
|
220
|
+
Signal() {
|
|
221
|
+
if (this._waiters.length > 0) {
|
|
222
|
+
const waiter = this._waiters.shift();
|
|
223
|
+
queueMicrotask(() => waiter());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// Wait atomically unlocks c.L and suspends execution of the calling goroutine
|
|
227
|
+
async Wait() {
|
|
228
|
+
this._l.Unlock();
|
|
229
|
+
return new Promise((resolve) => {
|
|
230
|
+
this._waiters.push(async () => {
|
|
231
|
+
await this._l.Lock();
|
|
232
|
+
resolve();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// clone returns a copy of this Cond instance
|
|
237
|
+
clone() {
|
|
238
|
+
return new Cond(this._l);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// NewCond returns a new Cond with Locker l
|
|
242
|
+
export function NewCond(l) {
|
|
243
|
+
return new Cond(l);
|
|
244
|
+
}
|
|
245
|
+
// Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines
|
|
246
|
+
export class Map {
|
|
247
|
+
_m = new RWMutex();
|
|
248
|
+
_data = new globalThis.Map();
|
|
249
|
+
constructor(init) {
|
|
250
|
+
// Map has no public fields to initialize
|
|
251
|
+
}
|
|
252
|
+
// Delete deletes the value for a key
|
|
253
|
+
async Delete(key) {
|
|
254
|
+
await this._m.Lock();
|
|
255
|
+
try {
|
|
256
|
+
this._data.delete(key);
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
this._m.Unlock();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Load returns the value stored in the map for a key, or nil if no value is present
|
|
263
|
+
async Load(key) {
|
|
264
|
+
await this._m.RLock();
|
|
265
|
+
try {
|
|
266
|
+
const value = this._data.get(key);
|
|
267
|
+
return [value, this._data.has(key)];
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
this._m.RUnlock();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// LoadAndDelete deletes the value for a key, returning the previous value if any
|
|
274
|
+
async LoadAndDelete(key) {
|
|
275
|
+
await this._m.Lock();
|
|
276
|
+
try {
|
|
277
|
+
const value = this._data.get(key);
|
|
278
|
+
const loaded = this._data.has(key);
|
|
279
|
+
this._data.delete(key);
|
|
280
|
+
return [value, loaded];
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
this._m.Unlock();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// LoadOrStore returns the existing value for the key if present
|
|
287
|
+
async LoadOrStore(key, value) {
|
|
288
|
+
await this._m.Lock();
|
|
289
|
+
try {
|
|
290
|
+
if (this._data.has(key)) {
|
|
291
|
+
return [this._data.get(key), true];
|
|
292
|
+
}
|
|
293
|
+
this._data.set(key, value);
|
|
294
|
+
return [value, false];
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
this._m.Unlock();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Range calls f sequentially for each key and value present in the map
|
|
301
|
+
async Range(f) {
|
|
302
|
+
await this._m.RLock();
|
|
303
|
+
try {
|
|
304
|
+
for (const [key, value] of this._data) {
|
|
305
|
+
if (!f(key, value)) {
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
this._m.RUnlock();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// Store sets the value for a key
|
|
315
|
+
async Store(key, value) {
|
|
316
|
+
await this._m.Lock();
|
|
317
|
+
try {
|
|
318
|
+
this._data.set(key, value);
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
this._m.Unlock();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// clone returns a copy of this Map instance
|
|
325
|
+
clone() {
|
|
326
|
+
return new Map();
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// Pool is a set of temporary objects that may be individually saved and retrieved
|
|
330
|
+
export class Pool {
|
|
331
|
+
New;
|
|
332
|
+
_pool = [];
|
|
333
|
+
constructor(init) {
|
|
334
|
+
this.New = init?.New;
|
|
335
|
+
}
|
|
336
|
+
// Get selects an arbitrary item from the Pool, removes it from the Pool, and returns it to the caller
|
|
337
|
+
Get() {
|
|
338
|
+
if (this._pool.length > 0) {
|
|
339
|
+
return this._pool.pop();
|
|
340
|
+
}
|
|
341
|
+
if (this.New) {
|
|
342
|
+
return this.New();
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
// Put adds x to the pool
|
|
347
|
+
Put(x) {
|
|
348
|
+
if (x !== null && x !== undefined) {
|
|
349
|
+
this._pool.push(x);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// clone returns a copy of this Pool instance
|
|
353
|
+
clone() {
|
|
354
|
+
return new Pool({ New: this.New });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// OnceFunc returns a function that invokes f only once
|
|
358
|
+
export function OnceFunc(f) {
|
|
359
|
+
let called = false;
|
|
360
|
+
return () => {
|
|
361
|
+
if (!called) {
|
|
362
|
+
called = true;
|
|
363
|
+
f();
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
// OnceValue returns a function that invokes f only once and returns the value returned by f
|
|
368
|
+
export function OnceValue(f) {
|
|
369
|
+
let value;
|
|
370
|
+
let called = false;
|
|
371
|
+
return () => {
|
|
372
|
+
if (!called) {
|
|
373
|
+
called = true;
|
|
374
|
+
value = f();
|
|
375
|
+
}
|
|
376
|
+
return value;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
// OnceValues returns a function that invokes f only once and returns the values returned by f
|
|
380
|
+
export function OnceValues(f) {
|
|
381
|
+
let value1;
|
|
382
|
+
let value2;
|
|
383
|
+
let called = false;
|
|
384
|
+
return () => {
|
|
385
|
+
if (!called) {
|
|
386
|
+
called = true;
|
|
387
|
+
[value1, value2] = f();
|
|
388
|
+
}
|
|
389
|
+
return [value1, value2];
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../gs/sync/sync.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,+EAA+E;AAC/E,8EAA8E;AAC9E,8BAA8B;AAQ9B,mCAAmC;AACnC,MAAM,OAAO,KAAK;IACR,OAAO,GAAY,KAAK,CAAA;IACxB,UAAU,GAAsB,EAAE,CAAA;IAE1C,YAAY,IAAkB;QAC5B,2CAA2C;IAC7C,CAAC;IAED,eAAe;IACf,2FAA2F;IACpF,KAAK,CAAC,IAAI;QACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;YACnB,OAAM;QACR,CAAC;QAED,2DAA2D;QAC3D,0DAA0D;QAC1D,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,2DAA2D;IACpD,OAAO;QACZ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;YACnB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,O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GAAG,KAAK,CAAA;IAClB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,CAAA;YACb,KAAK,GAAG,CAAC,EAAE,CAAA;QACb,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;AACH,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,UAAU,CAAS,CAAiB;IAClD,IAAI,MAAU,CAAA;IACd,IAAI,MAAU,CAAA;IACd,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,OAAO,GAAG,EAAE;QACV,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,CACZ;YAAA,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAA;QACzB,CAAC;QACD,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzB,CAAC,CAAA;AACH,CAAC"}
|
package/dist/gs/time/time.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export declare class Time {
|
|
|
2
2
|
private _date;
|
|
3
3
|
private _nsec;
|
|
4
4
|
private _monotonic?;
|
|
5
|
-
|
|
5
|
+
private _location;
|
|
6
|
+
constructor(date: globalThis.Date, nsec?: number, monotonic?: number, location?: Location);
|
|
6
7
|
clone(): Time;
|
|
8
|
+
Format(layout: string): string;
|
|
7
9
|
Sub(u: Time): Duration;
|
|
8
10
|
Add(d: Duration): Time;
|
|
9
11
|
Equal(u: Time): boolean;
|
|
@@ -25,8 +27,10 @@ export declare class Duration {
|
|
|
25
27
|
export declare function multiplyDuration(duration: Duration, multiplier: number): Duration;
|
|
26
28
|
export declare class Location {
|
|
27
29
|
private _name;
|
|
28
|
-
|
|
30
|
+
private _offsetSeconds?;
|
|
31
|
+
constructor(name: string, offsetSeconds?: number);
|
|
29
32
|
get name(): string;
|
|
33
|
+
get offsetSeconds(): number | undefined;
|
|
30
34
|
}
|
|
31
35
|
export declare enum Month {
|
|
32
36
|
January = 1,
|
|
@@ -45,6 +49,7 @@ export declare enum Month {
|
|
|
45
49
|
export declare function Now(): Time;
|
|
46
50
|
export declare function Date(year: number, month: Month, day: number, hour: number, min: number, sec: number, nsec: number, loc: Location): Time;
|
|
47
51
|
export declare const UTC: Location;
|
|
52
|
+
export declare function FixedZone(name: string, offset: number): Location;
|
|
48
53
|
export declare const Nanosecond: Duration;
|
|
49
54
|
export declare const Microsecond: Duration;
|
|
50
55
|
export declare const Millisecond: Duration;
|
|
@@ -55,3 +60,7 @@ export declare function Since(t: Time): Duration;
|
|
|
55
60
|
export declare function Until(t: Time): Duration;
|
|
56
61
|
export declare function Sleep(d: Duration): Promise<void>;
|
|
57
62
|
export declare const May = Month.May;
|
|
63
|
+
export declare const DateTime = "2006-01-02 15:04:05";
|
|
64
|
+
export declare const Layout = "01/02 03:04:05PM '06 -0700";
|
|
65
|
+
export declare const RFC3339 = "2006-01-02T15:04:05Z07:00";
|
|
66
|
+
export declare const Kitchen = "3:04PM";
|