firefly-compiler 0.4.4
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/.firefly-workspace +1 -0
- package/.vscode/settings.json +5 -0
- package/LICENSE.txt +21 -0
- package/README.md +96 -0
- package/bin/firefly.mjs +2 -0
- package/compiler/.firefly/package.ff +1 -0
- package/compiler/Builder.ff +218 -0
- package/compiler/Compiler.ff +241 -0
- package/compiler/Dependencies.ff +179 -0
- package/compiler/Deriver.ff +647 -0
- package/compiler/Dictionaries.ff +205 -0
- package/compiler/Environment.ff +166 -0
- package/compiler/Inference.ff +1117 -0
- package/compiler/JsEmitter.ff +861 -0
- package/compiler/JsImporter.ff +56 -0
- package/compiler/LspHook.ff +188 -0
- package/compiler/Main.ff +237 -0
- package/compiler/Parser.ff +1383 -0
- package/compiler/Patterns.ff +111 -0
- package/compiler/Resolver.ff +620 -0
- package/compiler/Substitution.ff +178 -0
- package/compiler/Syntax.ff +299 -0
- package/compiler/Token.ff +180 -0
- package/compiler/Tokenizer.ff +278 -0
- package/compiler/Unification.ff +220 -0
- package/compiler/Wildcards.ff +50 -0
- package/compiler/Workspace.ff +88 -0
- package/core/.firefly/package.ff +2 -0
- package/core/Any.ff +30 -0
- package/core/Array.ff +249 -0
- package/core/AssetSystem.ff +61 -0
- package/core/Atomic.ff +64 -0
- package/core/Bool.ff +13 -0
- package/core/BrowserSystem.ff +14 -0
- package/core/Buffer.ff +211 -0
- package/core/BuildSystem.ff +144 -0
- package/core/Channel.ff +131 -0
- package/core/Char.ff +18 -0
- package/core/Core.ff +58 -0
- package/core/Duration.ff +15 -0
- package/core/Equal.ff +52 -0
- package/core/Error.ff +20 -0
- package/core/FileHandle.ff +41 -0
- package/core/Float.ff +41 -0
- package/core/HttpClient.ff +84 -0
- package/core/Instant.ff +9 -0
- package/core/Int.ff +61 -0
- package/core/IntMap.ff +85 -0
- package/core/JsSystem.ff +66 -0
- package/core/JsValue.ff +240 -0
- package/core/List.ff +440 -0
- package/core/Lock.ff +144 -0
- package/core/Log.ff +24 -0
- package/core/Map.ff +126 -0
- package/core/NodeSystem.ff +88 -0
- package/core/Nothing.ff +1 -0
- package/core/Option.ff +133 -0
- package/core/Ordering.ff +157 -0
- package/core/Pair.ff +55 -0
- package/core/Path.ff +393 -0
- package/core/RbMap.ff +216 -0
- package/core/Serializable.ff +173 -0
- package/core/Set.ff +38 -0
- package/core/Show.ff +43 -0
- package/core/Stack.ff +263 -0
- package/core/Stream.ff +406 -0
- package/core/String.ff +175 -0
- package/core/StringMap.ff +85 -0
- package/core/Task.ff +138 -0
- package/core/Try.ff +81 -0
- package/core/Unit.ff +3 -0
- package/experimental/random/AltGeneric.ff +44 -0
- package/experimental/random/Async.ff +68 -0
- package/experimental/random/Buffer2.ff +77 -0
- package/experimental/random/Cat.ff +12 -0
- package/experimental/random/Dictionary.ff +52 -0
- package/experimental/random/Example.ff +46 -0
- package/experimental/random/Generic.ff +102 -0
- package/experimental/random/HappyEyeballs.ff +40 -0
- package/experimental/random/HashMap.ff +72 -0
- package/experimental/random/IfElseUnit.ff +9 -0
- package/experimental/random/InputOutput.ff +23 -0
- package/experimental/random/ListVsArray.ff +45 -0
- package/experimental/random/Main.ff +44 -0
- package/experimental/random/MapTest.ff +67 -0
- package/experimental/random/OldTaskSystem.ff +210 -0
- package/experimental/random/PatternTest.ff +39 -0
- package/experimental/random/Patterns.ff +226 -0
- package/experimental/random/ReadBytesTest.ff +10 -0
- package/experimental/random/RunLength.ff +65 -0
- package/experimental/random/Scrape.ff +51 -0
- package/experimental/random/Serialization.ff +217 -0
- package/experimental/random/SerializationTest.ff +46 -0
- package/experimental/random/Serializer.ff +36 -0
- package/experimental/random/StdInOutErr.ff +4 -0
- package/experimental/random/Symbols.ff +74 -0
- package/experimental/random/Tag.ff +49 -0
- package/experimental/random/Tensor.ff +52 -0
- package/experimental/random/Try.ff +56 -0
- package/experimental/random/Tsv.ff +9 -0
- package/experimental/random/TypesAreModules.ff +87 -0
- package/experimental/random/blueprints/Blueprint.ff +52 -0
- package/experimental/random/blueprints/Main.ff +11 -0
- package/experimental/random/blueprints/Pretty.ff +58 -0
- package/experimental/random/blueprints/User.ff +64 -0
- package/experimental/random/blueprintsystem/BlueprintSystem.ff +48 -0
- package/experimental/random/blueprintsystem/Deserialize.ff +53 -0
- package/experimental/random/blueprintsystem/ReadJs.ff +13 -0
- package/experimental/random/blueprintsystem/User.ff +2 -0
- package/experimental/random/kahrs/Kahrs.ff +112 -0
- package/experimental/random/kahrs/TestKahrs.ff +22 -0
- package/experimental/random/kahrs/TestMap.ff +18 -0
- package/experimental/random/streaming/Gzip.ff +3 -0
- package/experimental/random/streaming/Main.ff +34 -0
- package/experimental/random/streaming/S3Bucket.ff +11 -0
- package/experimental/random/streaming/Tar.ff +5 -0
- package/experimental/rhymeapp/Main.ff +81 -0
- package/experimental/rhymeapp/index.html +14 -0
- package/firefly.sh +5 -0
- package/fireflysite/Main.ff +13 -0
- package/httpserver/.firefly/package.ff +1 -0
- package/httpserver/HttpServer.ff +184 -0
- package/lsp/.firefly/package.ff +1 -0
- package/lsp/CompletionHandler.ff +814 -0
- package/lsp/Handler.ff +551 -0
- package/lsp/HoverHandler.ff +82 -0
- package/lsp/LanguageServer.ff +229 -0
- package/lsp/SignatureHelpHandler.ff +55 -0
- package/lsp/SymbolHandler.ff +167 -0
- package/output/js/ff/compiler/Builder.mjs +483 -0
- package/output/js/ff/compiler/Compiler.mjs +410 -0
- package/output/js/ff/compiler/Dependencies.mjs +388 -0
- package/output/js/ff/compiler/Deriver.mjs +1166 -0
- package/output/js/ff/compiler/Dictionaries.mjs +1305 -0
- package/output/js/ff/compiler/Environment.mjs +1005 -0
- package/output/js/ff/compiler/Inference.mjs +4264 -0
- package/output/js/ff/compiler/JsEmitter.mjs +5353 -0
- package/output/js/ff/compiler/JsImporter.mjs +262 -0
- package/output/js/ff/compiler/LspHook.mjs +789 -0
- package/output/js/ff/compiler/Main.mjs +1695 -0
- package/output/js/ff/compiler/Parser.mjs +4004 -0
- package/output/js/ff/compiler/Patterns.mjs +923 -0
- package/output/js/ff/compiler/Resolver.mjs +2303 -0
- package/output/js/ff/compiler/Substitution.mjs +1146 -0
- package/output/js/ff/compiler/Syntax.mjs +12430 -0
- package/output/js/ff/compiler/Token.mjs +3092 -0
- package/output/js/ff/compiler/Tokenizer.mjs +589 -0
- package/output/js/ff/compiler/Unification.mjs +1748 -0
- package/output/js/ff/compiler/Wildcards.mjs +604 -0
- package/output/js/ff/compiler/Workspace.mjs +683 -0
- package/output/js/ff/core/Any.mjs +139 -0
- package/output/js/ff/core/Array.mjs +594 -0
- package/output/js/ff/core/AssetSystem.mjs +270 -0
- package/output/js/ff/core/Atomic.mjs +186 -0
- package/output/js/ff/core/Bool.mjs +141 -0
- package/output/js/ff/core/BrowserSystem.mjs +122 -0
- package/output/js/ff/core/Buffer.mjs +467 -0
- package/output/js/ff/core/BuildSystem.mjs +320 -0
- package/output/js/ff/core/Channel.mjs +268 -0
- package/output/js/ff/core/Char.mjs +145 -0
- package/output/js/ff/core/Core.mjs +300 -0
- package/output/js/ff/core/Duration.mjs +112 -0
- package/output/js/ff/core/Equal.mjs +175 -0
- package/output/js/ff/core/Error.mjs +138 -0
- package/output/js/ff/core/FileHandle.mjs +164 -0
- package/output/js/ff/core/Float.mjs +214 -0
- package/output/js/ff/core/HttpClient.mjs +210 -0
- package/output/js/ff/core/Instant.mjs +105 -0
- package/output/js/ff/core/Int.mjs +254 -0
- package/output/js/ff/core/IntMap.mjs +282 -0
- package/output/js/ff/core/JsSystem.mjs +234 -0
- package/output/js/ff/core/JsValue.mjs +678 -0
- package/output/js/ff/core/List.mjs +2335 -0
- package/output/js/ff/core/Lock.mjs +322 -0
- package/output/js/ff/core/Log.mjs +159 -0
- package/output/js/ff/core/Map.mjs +358 -0
- package/output/js/ff/core/NodeSystem.mjs +288 -0
- package/output/js/ff/core/Nothing.mjs +100 -0
- package/output/js/ff/core/Option.mjs +1002 -0
- package/output/js/ff/core/Ordering.mjs +734 -0
- package/output/js/ff/core/Pair.mjs +318 -0
- package/output/js/ff/core/Path.mjs +768 -0
- package/output/js/ff/core/RbMap.mjs +1936 -0
- package/output/js/ff/core/Serializable.mjs +434 -0
- package/output/js/ff/core/Set.mjs +250 -0
- package/output/js/ff/core/Show.mjs +201 -0
- package/output/js/ff/core/Stack.mjs +595 -0
- package/output/js/ff/core/Stream.mjs +1300 -0
- package/output/js/ff/core/String.mjs +433 -0
- package/output/js/ff/core/StringMap.mjs +282 -0
- package/output/js/ff/core/Task.mjs +345 -0
- package/output/js/ff/core/Try.mjs +503 -0
- package/output/js/ff/core/Unit.mjs +103 -0
- package/package.json +29 -0
- package/postgresql/.firefly/include/package-lock.json +250 -0
- package/postgresql/.firefly/include/package.json +5 -0
- package/postgresql/.firefly/include/prepare.sh +2 -0
- package/postgresql/.firefly/package.ff +3 -0
- package/postgresql/Pg.ff +530 -0
- package/unsafejs/.firefly/package.ff +1 -0
- package/unsafejs/UnsafeJs.ff +19 -0
- package/vscode/.vscode/launch.json +18 -0
- package/vscode/.vscode/tasks.json +33 -0
- package/vscode/LICENSE.txt +21 -0
- package/vscode/Prepublish.ff +15 -0
- package/vscode/README.md +17 -0
- package/vscode/client/package-lock.json +544 -0
- package/vscode/client/package.json +22 -0
- package/vscode/client/src/extension.ts +64 -0
- package/vscode/client/tsconfig.json +12 -0
- package/vscode/icons/firefly-icon.png +0 -0
- package/vscode/icons/firefly-icon.svg +10 -0
- package/vscode/icons/firefly-logo-notext.png +0 -0
- package/vscode/icons/firefly-logo.png +0 -0
- package/vscode/language-configuration.json +39 -0
- package/vscode/package-lock.json +3623 -0
- package/vscode/package.json +144 -0
- package/vscode/snippets-none.json +1 -0
- package/vscode/snippets.json +241 -0
- package/vscode/syntaxes/firefly.tmLanguage.json +294 -0
- package/vscode/tsconfig.json +20 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import * as ff_core_Any from "../../ff/core/Any.mjs"
|
|
4
|
+
|
|
5
|
+
import * as ff_core_Array from "../../ff/core/Array.mjs"
|
|
6
|
+
|
|
7
|
+
import * as ff_core_AssetSystem from "../../ff/core/AssetSystem.mjs"
|
|
8
|
+
|
|
9
|
+
import * as ff_core_Atomic from "../../ff/core/Atomic.mjs"
|
|
10
|
+
|
|
11
|
+
import * as ff_core_Bool from "../../ff/core/Bool.mjs"
|
|
12
|
+
|
|
13
|
+
import * as ff_core_BrowserSystem from "../../ff/core/BrowserSystem.mjs"
|
|
14
|
+
|
|
15
|
+
import * as ff_core_Buffer from "../../ff/core/Buffer.mjs"
|
|
16
|
+
|
|
17
|
+
import * as ff_core_BuildSystem from "../../ff/core/BuildSystem.mjs"
|
|
18
|
+
|
|
19
|
+
import * as ff_core_Channel from "../../ff/core/Channel.mjs"
|
|
20
|
+
|
|
21
|
+
import * as ff_core_Char from "../../ff/core/Char.mjs"
|
|
22
|
+
|
|
23
|
+
import * as ff_core_Core from "../../ff/core/Core.mjs"
|
|
24
|
+
|
|
25
|
+
import * as ff_core_Duration from "../../ff/core/Duration.mjs"
|
|
26
|
+
|
|
27
|
+
import * as ff_core_Equal from "../../ff/core/Equal.mjs"
|
|
28
|
+
|
|
29
|
+
import * as ff_core_Error from "../../ff/core/Error.mjs"
|
|
30
|
+
|
|
31
|
+
import * as ff_core_FileHandle from "../../ff/core/FileHandle.mjs"
|
|
32
|
+
|
|
33
|
+
import * as ff_core_Float from "../../ff/core/Float.mjs"
|
|
34
|
+
|
|
35
|
+
import * as ff_core_HttpClient from "../../ff/core/HttpClient.mjs"
|
|
36
|
+
|
|
37
|
+
import * as ff_core_Instant from "../../ff/core/Instant.mjs"
|
|
38
|
+
|
|
39
|
+
import * as ff_core_Int from "../../ff/core/Int.mjs"
|
|
40
|
+
|
|
41
|
+
import * as ff_core_IntMap from "../../ff/core/IntMap.mjs"
|
|
42
|
+
|
|
43
|
+
import * as ff_core_JsSystem from "../../ff/core/JsSystem.mjs"
|
|
44
|
+
|
|
45
|
+
import * as ff_core_JsValue from "../../ff/core/JsValue.mjs"
|
|
46
|
+
|
|
47
|
+
import * as ff_core_List from "../../ff/core/List.mjs"
|
|
48
|
+
|
|
49
|
+
import * as ff_core_Lock from "../../ff/core/Lock.mjs"
|
|
50
|
+
|
|
51
|
+
import * as ff_core_Log from "../../ff/core/Log.mjs"
|
|
52
|
+
|
|
53
|
+
import * as ff_core_Map from "../../ff/core/Map.mjs"
|
|
54
|
+
|
|
55
|
+
import * as ff_core_NodeSystem from "../../ff/core/NodeSystem.mjs"
|
|
56
|
+
|
|
57
|
+
import * as ff_core_Nothing from "../../ff/core/Nothing.mjs"
|
|
58
|
+
|
|
59
|
+
import * as ff_core_Option from "../../ff/core/Option.mjs"
|
|
60
|
+
|
|
61
|
+
import * as ff_core_Ordering from "../../ff/core/Ordering.mjs"
|
|
62
|
+
|
|
63
|
+
import * as ff_core_Pair from "../../ff/core/Pair.mjs"
|
|
64
|
+
|
|
65
|
+
import * as ff_core_Path from "../../ff/core/Path.mjs"
|
|
66
|
+
|
|
67
|
+
import * as ff_core_Serializable from "../../ff/core/Serializable.mjs"
|
|
68
|
+
|
|
69
|
+
import * as ff_core_Set from "../../ff/core/Set.mjs"
|
|
70
|
+
|
|
71
|
+
import * as ff_core_Show from "../../ff/core/Show.mjs"
|
|
72
|
+
|
|
73
|
+
import * as ff_core_Stack from "../../ff/core/Stack.mjs"
|
|
74
|
+
|
|
75
|
+
import * as ff_core_Stream from "../../ff/core/Stream.mjs"
|
|
76
|
+
|
|
77
|
+
import * as ff_core_String from "../../ff/core/String.mjs"
|
|
78
|
+
|
|
79
|
+
import * as ff_core_StringMap from "../../ff/core/StringMap.mjs"
|
|
80
|
+
|
|
81
|
+
import * as ff_core_Task from "../../ff/core/Task.mjs"
|
|
82
|
+
|
|
83
|
+
import * as ff_core_Try from "../../ff/core/Try.mjs"
|
|
84
|
+
|
|
85
|
+
import * as ff_core_Unit from "../../ff/core/Unit.mjs"
|
|
86
|
+
|
|
87
|
+
// type Task
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
export function Task_spawn(self_, body_) {
|
|
97
|
+
|
|
98
|
+
ff_core_Task.Task_throwIfAborted(self_)
|
|
99
|
+
const task = {controller: new AbortController(), subtasks: new Set(), started: performance.now() * 0.001}
|
|
100
|
+
self_.subtasks.add(task)
|
|
101
|
+
task.promise = Promise.resolve(task).then(async () => {
|
|
102
|
+
try {
|
|
103
|
+
await body_(task, task)
|
|
104
|
+
} catch(e) {
|
|
105
|
+
await ff_core_Task.Task_abort$(self_)
|
|
106
|
+
throw e
|
|
107
|
+
} finally {
|
|
108
|
+
for(const subtask of task.subtasks) subtask.controller.abort()
|
|
109
|
+
await Promise.allSettled([...task.subtasks].map(subtask => subtask.promise))
|
|
110
|
+
self_.subtasks.delete(task)
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
return task
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function Task_throwIfAborted(self_) {
|
|
118
|
+
|
|
119
|
+
if(self_.controller.signal.aborted) {
|
|
120
|
+
const signal = self_.controller.signal
|
|
121
|
+
self_.controller = new AbortController()
|
|
122
|
+
signal.throwIfAborted()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function Task_abort(self_) {
|
|
128
|
+
throw new Error('Function Task_abort is missing on this target in sync context.');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function Task_channel(self_, capacity_ = 0) {
|
|
132
|
+
return {capacity: capacity_, buffer: [], readers: new Set(), writers: new Set()}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function Task_lock(self_) {
|
|
136
|
+
throw new Error('Function Task_lock is missing on this target in sync context.');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function Task_now(self_) {
|
|
140
|
+
return Date.now() * 0.001
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function Task_elapsed(self_) {
|
|
144
|
+
return performance.now() * 0.001 - self_.started
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function Task_time(self_, body_) {
|
|
148
|
+
const start_ = ff_core_Task.Task_elapsed(self_);
|
|
149
|
+
const result_ = body_();
|
|
150
|
+
const stop_ = ff_core_Task.Task_elapsed(self_);
|
|
151
|
+
const duration_ = (stop_ - start_);
|
|
152
|
+
return ff_core_Pair.Pair(result_, duration_)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function Task_spawn$(self_, body_, $task) {
|
|
156
|
+
|
|
157
|
+
return ff_core_Task.Task_spawn(self_, body_)
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function Task_throwIfAborted$(self_, $task) {
|
|
162
|
+
|
|
163
|
+
ff_core_Task.Task_throwIfAborted(self_)
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function Task_abort$(self_, $task) {
|
|
168
|
+
|
|
169
|
+
self_.controller.abort()
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function Task_channel$(self_, capacity_ = 0, $task) {
|
|
174
|
+
return ff_core_Task.Task_channel(capacity_)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function Task_lock$(self_, $task) {
|
|
178
|
+
return {owner: null, level: 0, stack: [], queue: []}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function Task_now$(self_, $task) {
|
|
182
|
+
return Date.now() * 0.001
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export async function Task_elapsed$(self_, $task) {
|
|
186
|
+
return performance.now() * 0.001 - self_.started
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export async function Task_time$(self_, body_, $task) {
|
|
190
|
+
const start_ = (await ff_core_Task.Task_elapsed$(self_, $task));
|
|
191
|
+
const result_ = (await body_($task));
|
|
192
|
+
const stop_ = (await ff_core_Task.Task_elapsed$(self_, $task));
|
|
193
|
+
const duration_ = (stop_ - start_);
|
|
194
|
+
return ff_core_Pair.Pair(result_, duration_)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function Task_sleep(self_, duration_) {
|
|
198
|
+
ff_core_Channel.ChannelAction_timeout(ff_core_Channel.readOr_(ff_core_Task.Task_channel(self_, 0), ((_) => {
|
|
199
|
+
|
|
200
|
+
})), duration_, (() => {
|
|
201
|
+
|
|
202
|
+
}))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function Task_all(self_, tasks_) {
|
|
206
|
+
const successChannel_ = ff_core_Task.Task_channel(self_, 0);
|
|
207
|
+
const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
|
|
208
|
+
ff_core_Task.Task_spawn(self_, ((t_) => {
|
|
209
|
+
const channel_ = ff_core_Task.Task_channel(t_, 0);
|
|
210
|
+
ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
|
|
211
|
+
ff_core_List.List_each(ff_core_List.List_pairs(tasks_), ((_1) => {
|
|
212
|
+
{
|
|
213
|
+
const i_ = _1.first_;
|
|
214
|
+
const task_ = _1.second_;
|
|
215
|
+
ff_core_Task.Task_spawn(t_, ((_) => {
|
|
216
|
+
ff_core_Channel.Channel_write(channel_, ff_core_Pair.Pair(i_, task_()))
|
|
217
|
+
}))
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
const result_ = ff_core_List.List_map(ff_core_List.List_sortBy(ff_core_List.List_map(tasks_, ((_) => {
|
|
222
|
+
return ff_core_Channel.Channel_read(channel_)
|
|
223
|
+
})), ((_w1) => {
|
|
224
|
+
return _w1.first_
|
|
225
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
|
|
226
|
+
return _w1.second_
|
|
227
|
+
}));
|
|
228
|
+
return ff_core_Channel.Channel_write(successChannel_, result_)
|
|
229
|
+
})), ((error_) => {
|
|
230
|
+
ff_core_Channel.Channel_write(failureChannel_, error_);
|
|
231
|
+
ff_core_Task.Task_abort(t_)
|
|
232
|
+
})))
|
|
233
|
+
}));
|
|
234
|
+
return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
|
|
235
|
+
return _w1
|
|
236
|
+
})), failureChannel_, ((_w1) => {
|
|
237
|
+
return ff_core_Error.Error_rethrow(_w1)
|
|
238
|
+
})))
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function Task_race(self_, tasks_) {
|
|
242
|
+
const successChannel_ = ff_core_Task.Task_channel(self_, 0);
|
|
243
|
+
const failureChannel_ = ff_core_Task.Task_channel(self_, 0);
|
|
244
|
+
let live_ = ff_core_List.List_size(tasks_);
|
|
245
|
+
const started_ = ff_core_List.List_map(tasks_, ((task_) => {
|
|
246
|
+
return ff_core_Task.Task_spawn(self_, ((_) => {
|
|
247
|
+
ff_core_Try.Try_grab(ff_core_Try.Try_catchAny(ff_core_Core.try_((() => {
|
|
248
|
+
return ff_core_Channel.Channel_write(successChannel_, task_())
|
|
249
|
+
})), ((e_) => {
|
|
250
|
+
live_ -= 1;
|
|
251
|
+
if((live_ === 0)) {
|
|
252
|
+
ff_core_Channel.Channel_write(failureChannel_, e_)
|
|
253
|
+
}
|
|
254
|
+
})))
|
|
255
|
+
}))
|
|
256
|
+
}));
|
|
257
|
+
try {
|
|
258
|
+
return ff_core_Channel.ChannelAction_wait(ff_core_Channel.ChannelAction_readOr(ff_core_Channel.readOr_(successChannel_, ((_w1) => {
|
|
259
|
+
return _w1
|
|
260
|
+
})), failureChannel_, ((_w1) => {
|
|
261
|
+
return ff_core_Error.Error_rethrow(_w1)
|
|
262
|
+
})))
|
|
263
|
+
} finally {
|
|
264
|
+
ff_core_List.List_each(started_, ((_w1) => {
|
|
265
|
+
ff_core_Task.Task_abort(_w1)
|
|
266
|
+
}))
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export async function Task_sleep$(self_, duration_, $task) {
|
|
271
|
+
(await ff_core_Channel.ChannelAction_timeout$((await ff_core_Channel.readOr_$((await ff_core_Task.Task_channel$(self_, 0, $task)), (async (_, $task) => {
|
|
272
|
+
|
|
273
|
+
}), $task)), duration_, (async ($task) => {
|
|
274
|
+
|
|
275
|
+
}), $task))
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export async function Task_all$(self_, tasks_, $task) {
|
|
279
|
+
const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
|
|
280
|
+
const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
|
|
281
|
+
(await ff_core_Task.Task_spawn$(self_, (async (t_, $task) => {
|
|
282
|
+
const channel_ = (await ff_core_Task.Task_channel$(t_, 0, $task));
|
|
283
|
+
ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
|
|
284
|
+
(await ff_core_List.List_each$(ff_core_List.List_pairs(tasks_), (async (_1, $task) => {
|
|
285
|
+
{
|
|
286
|
+
const i_ = _1.first_;
|
|
287
|
+
const task_ = _1.second_;
|
|
288
|
+
(await ff_core_Task.Task_spawn$(t_, (async (_, $task) => {
|
|
289
|
+
(await ff_core_Channel.Channel_write$(channel_, ff_core_Pair.Pair(i_, (await task_($task))), $task))
|
|
290
|
+
}), $task))
|
|
291
|
+
return
|
|
292
|
+
}
|
|
293
|
+
}), $task));
|
|
294
|
+
const result_ = ff_core_List.List_map(ff_core_List.List_sortBy((await ff_core_List.List_map$(tasks_, (async (_, $task) => {
|
|
295
|
+
return (await ff_core_Channel.Channel_read$(channel_, $task))
|
|
296
|
+
}), $task)), ((_w1) => {
|
|
297
|
+
return _w1.first_
|
|
298
|
+
}), ff_core_Ordering.ff_core_Ordering_Order$ff_core_Int_Int), ((_w1) => {
|
|
299
|
+
return _w1.second_
|
|
300
|
+
}));
|
|
301
|
+
return (await ff_core_Channel.Channel_write$(successChannel_, result_, $task))
|
|
302
|
+
}), $task)), (async (error_, $task) => {
|
|
303
|
+
(await ff_core_Channel.Channel_write$(failureChannel_, error_, $task));
|
|
304
|
+
(await ff_core_Task.Task_abort$(t_, $task))
|
|
305
|
+
}), $task)))
|
|
306
|
+
}), $task));
|
|
307
|
+
return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
|
|
308
|
+
return _w1
|
|
309
|
+
}), $task)), failureChannel_, (async (_w1, $task) => {
|
|
310
|
+
return ff_core_Error.Error_rethrow(_w1)
|
|
311
|
+
}), $task)), $task))
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export async function Task_race$(self_, tasks_, $task) {
|
|
315
|
+
const successChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
|
|
316
|
+
const failureChannel_ = (await ff_core_Task.Task_channel$(self_, 0, $task));
|
|
317
|
+
let live_ = ff_core_List.List_size(tasks_);
|
|
318
|
+
const started_ = (await ff_core_List.List_map$(tasks_, (async (task_, $task) => {
|
|
319
|
+
return (await ff_core_Task.Task_spawn$(self_, (async (_, $task) => {
|
|
320
|
+
ff_core_Try.Try_grab((await ff_core_Try.Try_catchAny$((await ff_core_Core.try_$((async ($task) => {
|
|
321
|
+
return (await ff_core_Channel.Channel_write$(successChannel_, (await task_($task)), $task))
|
|
322
|
+
}), $task)), (async (e_, $task) => {
|
|
323
|
+
live_ -= 1;
|
|
324
|
+
if((live_ === 0)) {
|
|
325
|
+
(await ff_core_Channel.Channel_write$(failureChannel_, e_, $task))
|
|
326
|
+
}
|
|
327
|
+
}), $task)))
|
|
328
|
+
}), $task))
|
|
329
|
+
}), $task));
|
|
330
|
+
try {
|
|
331
|
+
return (await ff_core_Channel.ChannelAction_wait$((await ff_core_Channel.ChannelAction_readOr$((await ff_core_Channel.readOr_$(successChannel_, (async (_w1, $task) => {
|
|
332
|
+
return _w1
|
|
333
|
+
}), $task)), failureChannel_, (async (_w1, $task) => {
|
|
334
|
+
return ff_core_Error.Error_rethrow(_w1)
|
|
335
|
+
}), $task)), $task))
|
|
336
|
+
} finally {
|
|
337
|
+
(await ff_core_List.List_each$(started_, (async (_w1, $task) => {
|
|
338
|
+
(await ff_core_Task.Task_abort$(_w1, $task))
|
|
339
|
+
}), $task))
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|