t-tasks 2.0.0 → 2.1.0
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/dist/t-tasks.d.ts +142 -19
- package/dist/t-tasks.esm.js +43 -17
- package/dist/t-tasks.esm.js.map +1 -1
- package/dist/t-tasks.js +43 -17
- package/dist/t-tasks.js.map +1 -1
- package/package.json +1 -1
- package/src/either.ts +62 -5
- package/src/maybe.ts +54 -3
- package/src/task.ts +108 -47
package/dist/t-tasks.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface Just<R> {
|
|
|
60
60
|
* Applied to 'just value' returns self without invoking transformer
|
|
61
61
|
* Applied to 'nothing' returns 'just op()'
|
|
62
62
|
*
|
|
63
|
+
* @template R2 transformer function's return type
|
|
63
64
|
* @param op function to be invoked
|
|
64
65
|
* @returns 'just value' or 'just op()'
|
|
65
66
|
*/
|
|
@@ -85,6 +86,18 @@ export interface Just<R> {
|
|
|
85
86
|
just: (value: R) => R2;
|
|
86
87
|
nothing: () => R3;
|
|
87
88
|
}): R2 | R3;
|
|
89
|
+
/**
|
|
90
|
+
* Maybe pattern matching transformer function
|
|
91
|
+
*
|
|
92
|
+
* Applied to 'just value' returns 'just op.just(value)'
|
|
93
|
+
* Applied to 'nothing' returns 'just op.nothing()'
|
|
94
|
+
*
|
|
95
|
+
* @template R2 just transformer function's return type
|
|
96
|
+
* @template R3 nothing transformer function's return type
|
|
97
|
+
* @param op.just transformer to be invoked with underlying value in case of just
|
|
98
|
+
* @param op.nothing transformer to be invoked in case of nothing
|
|
99
|
+
* @returns 'just op.just(value)' or 'just op.nothing()'
|
|
100
|
+
*/
|
|
88
101
|
matchMap<R2, R3 = R2>(this: Just<R>, op: {
|
|
89
102
|
just: (value: R) => R2;
|
|
90
103
|
nothing: () => R3;
|
|
@@ -248,6 +261,8 @@ export interface Just<R> {
|
|
|
248
261
|
* Absolutely Nothing
|
|
249
262
|
*
|
|
250
263
|
* Maybe data type specialization representing an absence of any value
|
|
264
|
+
*
|
|
265
|
+
* @template R underlying value
|
|
251
266
|
*/
|
|
252
267
|
export interface Nothing<R> {
|
|
253
268
|
/**
|
|
@@ -302,6 +317,7 @@ export interface Nothing<R> {
|
|
|
302
317
|
* Applied to 'just value' returns self without invoking transformer
|
|
303
318
|
* Applied to 'nothing' returns 'just op()'
|
|
304
319
|
*
|
|
320
|
+
* @template R2 transformer function's return type
|
|
305
321
|
* @param op function to be invoked
|
|
306
322
|
* @returns 'just value' or 'just op()'
|
|
307
323
|
*/
|
|
@@ -327,6 +343,18 @@ export interface Nothing<R> {
|
|
|
327
343
|
just: (value: R) => R2;
|
|
328
344
|
nothing: () => R3;
|
|
329
345
|
}): R2 | R3;
|
|
346
|
+
/**
|
|
347
|
+
* Maybe pattern matching transformer function
|
|
348
|
+
*
|
|
349
|
+
* Applied to 'just value' returns 'just op.just(value)'
|
|
350
|
+
* Applied to 'nothing' returns 'just op.nothing()'
|
|
351
|
+
*
|
|
352
|
+
* @template R2 just transformer function's return type
|
|
353
|
+
* @template R3 nothing transformer function's return type
|
|
354
|
+
* @param op.just transformer to be invoked with underlying value in case of just
|
|
355
|
+
* @param op.nothing transformer to be invoked in case of nothing
|
|
356
|
+
* @returns 'just op.just(value)' or 'just op.nothing()'
|
|
357
|
+
*/
|
|
330
358
|
matchMap<R2, R3 = R2>(this: Nothing<R>, op: {
|
|
331
359
|
just: (value: R) => R2;
|
|
332
360
|
nothing: () => R3;
|
|
@@ -508,7 +536,22 @@ export declare namespace Just {
|
|
|
508
536
|
function just<R>(just: Just<R>): R;
|
|
509
537
|
}
|
|
510
538
|
export declare namespace Nothing {}
|
|
539
|
+
/**
|
|
540
|
+
* Maybe generator
|
|
541
|
+
*
|
|
542
|
+
* @template T yielded underlying type
|
|
543
|
+
* @template TT yielded Maybe type
|
|
544
|
+
* @template R returned underlying type
|
|
545
|
+
*/
|
|
511
546
|
export type MaybeGenerator<T, TT extends Maybe<T>, R> = Generator<TT, R, T>;
|
|
547
|
+
/**
|
|
548
|
+
* Function returning Maybe generator (generator function)
|
|
549
|
+
*
|
|
550
|
+
* @template A argument types
|
|
551
|
+
* @template T yielded underlying type
|
|
552
|
+
* @template TT yielded Maybe type
|
|
553
|
+
* @template R returned underlying type
|
|
554
|
+
*/
|
|
512
555
|
export type MaybeGeneratorFunction<A extends unknown[], T, TT extends Maybe<T>, R> = (...args: A) => MaybeGenerator<T, TT, R>;
|
|
513
556
|
export declare namespace Maybe {
|
|
514
557
|
/**
|
|
@@ -530,6 +573,7 @@ export declare namespace Maybe {
|
|
|
530
573
|
*
|
|
531
574
|
* Resolves to 'nothing' in case of undefined value and 'just value' otherwise
|
|
532
575
|
*
|
|
576
|
+
* @template R underlying type
|
|
533
577
|
* @param value possibly undefined value
|
|
534
578
|
* @returns either 'just value' or 'nothing'
|
|
535
579
|
*/
|
|
@@ -541,7 +585,8 @@ export declare namespace Maybe {
|
|
|
541
585
|
*
|
|
542
586
|
* Resolves to 'nothing' in case of undefined or null value and 'just value' otherwise
|
|
543
587
|
*
|
|
544
|
-
* @
|
|
588
|
+
* @template R underlying type
|
|
589
|
+
* @param value possibly undefined or null value
|
|
545
590
|
* @returns either 'just value' or 'nothing'
|
|
546
591
|
*/
|
|
547
592
|
function fromNullable(value: undefined): Nothing<never>;
|
|
@@ -586,6 +631,7 @@ export declare namespace Maybe {
|
|
|
586
631
|
/**
|
|
587
632
|
* Standalone list predicate
|
|
588
633
|
*
|
|
634
|
+
* @template R underlying value type
|
|
589
635
|
* @param maybes a list of Maybe
|
|
590
636
|
* @returns true in case every list element is Just
|
|
591
637
|
*/
|
|
@@ -593,6 +639,7 @@ export declare namespace Maybe {
|
|
|
593
639
|
/**
|
|
594
640
|
* Standalone list predicate
|
|
595
641
|
*
|
|
642
|
+
* @template R underlying value type
|
|
596
643
|
* @param maybes a list of Maybe
|
|
597
644
|
* @returns true in case at least one list element is Just
|
|
598
645
|
*/
|
|
@@ -600,6 +647,7 @@ export declare namespace Maybe {
|
|
|
600
647
|
/**
|
|
601
648
|
* Standalone list predicate
|
|
602
649
|
*
|
|
650
|
+
* @template R underlying value type
|
|
603
651
|
* @param maybes a list of Maybe
|
|
604
652
|
* @returns true in case every list element is Nothing
|
|
605
653
|
*/
|
|
@@ -607,6 +655,7 @@ export declare namespace Maybe {
|
|
|
607
655
|
/**
|
|
608
656
|
* Standalone list predicate
|
|
609
657
|
*
|
|
658
|
+
* @template R underlying value type
|
|
610
659
|
* @param maybes a list of Maybe
|
|
611
660
|
* @returns true in case at least one list element is Nothing
|
|
612
661
|
*/
|
|
@@ -617,6 +666,7 @@ export declare namespace Maybe {
|
|
|
617
666
|
* Applying yield to a Maybe within the generator function unwraps the Maybe and returns underlying value in case of success
|
|
618
667
|
* However the convenient option for typescript is to use ```yield* maybe.generator()``` as otherwise one may have to deal with union types
|
|
619
668
|
*
|
|
669
|
+
* @template T yielded underlying type
|
|
620
670
|
* @template TT yielded Maybe type
|
|
621
671
|
* @template R returned underlying type
|
|
622
672
|
* @param maybeGeneratorFunction Maybe generator function
|
|
@@ -688,6 +738,7 @@ export interface Right<R, L> {
|
|
|
688
738
|
* Applied to 'right value' returns self without invoking transformer
|
|
689
739
|
* Applied to 'left error' returns 'right op(error)'
|
|
690
740
|
*
|
|
741
|
+
* @template R2 transformer function's return type
|
|
691
742
|
* @param op transformer to be invoked with underlying error
|
|
692
743
|
* @returns 'right value' or 'right op(error)'
|
|
693
744
|
*/
|
|
@@ -713,6 +764,18 @@ export interface Right<R, L> {
|
|
|
713
764
|
right: (value: R) => R2;
|
|
714
765
|
left: (error: L) => R3;
|
|
715
766
|
}): R2 | R3;
|
|
767
|
+
/**
|
|
768
|
+
* Either pattern matching transformer function
|
|
769
|
+
*
|
|
770
|
+
* Applied to 'right value' returns 'right op.right(value)'
|
|
771
|
+
* Applied to 'left error' returns 'right op.left(error)'
|
|
772
|
+
*
|
|
773
|
+
* @template R2 right transformer function's return type
|
|
774
|
+
* @template R3 left transformer function's return type
|
|
775
|
+
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
776
|
+
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
777
|
+
* @returns 'right op.right(value)' or 'right op.left(error)'
|
|
778
|
+
*/
|
|
716
779
|
matchMap<R2, R3 = R2>(this: Right<R, L>, op: {
|
|
717
780
|
right: (value: R) => R2;
|
|
718
781
|
left: (error: L) => R3;
|
|
@@ -739,7 +802,7 @@ export interface Right<R, L> {
|
|
|
739
802
|
chain<R2, L2>(this: Either<R, L>, op: (value: R) => Left<R2, L2>): Left<never, L | L2>;
|
|
740
803
|
chain<R2, L2>(this: Either<R, L>, op: (value: R) => Either<R2, L2>): Either<R2, L | L2>;
|
|
741
804
|
/**
|
|
742
|
-
* Either composition function
|
|
805
|
+
* Either fallback composition function
|
|
743
806
|
*
|
|
744
807
|
* Applied to 'right value' returns self without invoking composition function
|
|
745
808
|
* Applied to 'left error' returns 'op(error)'
|
|
@@ -767,7 +830,7 @@ export interface Right<R, L> {
|
|
|
767
830
|
* @template L3 left transformer function result's underlying error type
|
|
768
831
|
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
769
832
|
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
770
|
-
* @returns 'op(value)' or 'op(error)'
|
|
833
|
+
* @returns 'op.right(value)' or 'op.left(error)'
|
|
771
834
|
*/
|
|
772
835
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Right<R, L>, op: {
|
|
773
836
|
right: (value: R) => Right<R2, L2>;
|
|
@@ -938,6 +1001,7 @@ export interface Left<R, L> {
|
|
|
938
1001
|
* Applied to 'right value' returns self without invoking transformer
|
|
939
1002
|
* Applied to 'left error' returns 'right op(error)'
|
|
940
1003
|
*
|
|
1004
|
+
* @template R2 transformer function's return type
|
|
941
1005
|
* @param op transformer to be invoked with underlying error
|
|
942
1006
|
* @returns 'right value' or 'right op(error)'
|
|
943
1007
|
*/
|
|
@@ -963,6 +1027,18 @@ export interface Left<R, L> {
|
|
|
963
1027
|
right: (value: R) => R2;
|
|
964
1028
|
left: (error: L) => R3;
|
|
965
1029
|
}): R2 | R3;
|
|
1030
|
+
/**
|
|
1031
|
+
* Either pattern matching transformer function
|
|
1032
|
+
*
|
|
1033
|
+
* Applied to 'right value' returns 'right op.right(value)'
|
|
1034
|
+
* Applied to 'left error' returns 'right op.left(error)'
|
|
1035
|
+
*
|
|
1036
|
+
* @template R2 right transformer function's return type
|
|
1037
|
+
* @template R3 left transformer function's return type
|
|
1038
|
+
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
1039
|
+
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
1040
|
+
* @returns 'right op.right(value)' or 'right op.left(error)'
|
|
1041
|
+
*/
|
|
966
1042
|
matchMap<R2, R3 = R2>(this: Left<R, L>, op: {
|
|
967
1043
|
right: (value: R) => R2;
|
|
968
1044
|
left: (error: L) => R3;
|
|
@@ -1017,7 +1093,7 @@ export interface Left<R, L> {
|
|
|
1017
1093
|
* @template L3 left transformer function result's underlying error type
|
|
1018
1094
|
* @param op.right transformer to be invoked with underlying value in case of 'right'
|
|
1019
1095
|
* @param op.left transformer to be invoked with underlying error in case of 'left'
|
|
1020
|
-
* @returns 'op(value)' or 'op(error)'
|
|
1096
|
+
* @returns 'op.right(value)' or 'op.left(error)'
|
|
1021
1097
|
*/
|
|
1022
1098
|
matchChain<R2, L2, R3 = R2, L3 = L2>(this: Left<R, L>, op: {
|
|
1023
1099
|
right: (value: R) => Right<R2, L2>;
|
|
@@ -1162,7 +1238,22 @@ export declare namespace Left {
|
|
|
1162
1238
|
*/
|
|
1163
1239
|
function left<R, L>(left: Left<R, L>): L;
|
|
1164
1240
|
}
|
|
1241
|
+
/**
|
|
1242
|
+
* Either generator
|
|
1243
|
+
*
|
|
1244
|
+
* @template T yielded underlying type
|
|
1245
|
+
* @template TT yielded Either type
|
|
1246
|
+
* @template R returned underlying type
|
|
1247
|
+
*/
|
|
1165
1248
|
export type EitherGenerator<T, TT extends Either<T, any>, R> = Generator<TT, R, T>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Function returning Either generator (generator function)
|
|
1251
|
+
*
|
|
1252
|
+
* @template A argument types
|
|
1253
|
+
* @template T yielded underlying type
|
|
1254
|
+
* @template TT yielded Either type
|
|
1255
|
+
* @template R returned underlying type
|
|
1256
|
+
*/
|
|
1166
1257
|
export type EitherGeneratorFunction<A extends unknown[], T, TT extends Either<T, any>, R> = (...args: A) => EitherGenerator<T, TT, R>;
|
|
1167
1258
|
export declare namespace Either {
|
|
1168
1259
|
/**
|
|
@@ -1186,6 +1277,8 @@ export declare namespace Either {
|
|
|
1186
1277
|
*
|
|
1187
1278
|
* Resolves to 'left error' in case of undefined value and 'right value' otherwise
|
|
1188
1279
|
*
|
|
1280
|
+
* @template R underlying value type
|
|
1281
|
+
* @template L underlying error type
|
|
1189
1282
|
* @param value possibly undefined value
|
|
1190
1283
|
* @param error error to use in case of undefined value
|
|
1191
1284
|
* @returns either 'right value' or 'left error'
|
|
@@ -1198,8 +1291,10 @@ export declare namespace Either {
|
|
|
1198
1291
|
*
|
|
1199
1292
|
* Resolves to 'left error' in case of undefined or null value and 'right value' otherwise
|
|
1200
1293
|
*
|
|
1201
|
-
* @
|
|
1202
|
-
* @
|
|
1294
|
+
* @template R underlying value type
|
|
1295
|
+
* @template L underlying error type
|
|
1296
|
+
* @param value possibly undefined or null value
|
|
1297
|
+
* @param error error to use in case of undefined or null value
|
|
1203
1298
|
* @returns either 'right value' or 'left error'
|
|
1204
1299
|
*/
|
|
1205
1300
|
function fromNullable<L>(value: undefined, error: L): Left<never, L>;
|
|
@@ -1228,6 +1323,7 @@ export declare namespace Either {
|
|
|
1228
1323
|
* Useful for passing as a predicate to collection transformers
|
|
1229
1324
|
*
|
|
1230
1325
|
* @template R underlying value type
|
|
1326
|
+
* @template L underlying error type
|
|
1231
1327
|
* @param either Either instance
|
|
1232
1328
|
* @returns 'true' in case argument is 'right value' (and resolves type to be 'right')
|
|
1233
1329
|
*/
|
|
@@ -1238,6 +1334,7 @@ export declare namespace Either {
|
|
|
1238
1334
|
* Useful for passing as a predicate to collection transformers
|
|
1239
1335
|
*
|
|
1240
1336
|
* @template R underlying value type
|
|
1337
|
+
* @template L underlying error type
|
|
1241
1338
|
* @param either Either instance
|
|
1242
1339
|
* @returns 'true' in case argument is 'left error' (and resolves type to be 'left')
|
|
1243
1340
|
*/
|
|
@@ -1245,6 +1342,8 @@ export declare namespace Either {
|
|
|
1245
1342
|
/**
|
|
1246
1343
|
* Standalone list predicate
|
|
1247
1344
|
*
|
|
1345
|
+
* @template R underlying value type
|
|
1346
|
+
* @template L underlying error type
|
|
1248
1347
|
* @param eithers a list of Either
|
|
1249
1348
|
* @returns true in case every list element is Right
|
|
1250
1349
|
*/
|
|
@@ -1252,6 +1351,8 @@ export declare namespace Either {
|
|
|
1252
1351
|
/**
|
|
1253
1352
|
* Standalone list predicate
|
|
1254
1353
|
*
|
|
1354
|
+
* @template R underlying value type
|
|
1355
|
+
* @template L underlying error type
|
|
1255
1356
|
* @param eithers a list of Either
|
|
1256
1357
|
* @returns true in case at least one list element is Right
|
|
1257
1358
|
*/
|
|
@@ -1259,6 +1360,8 @@ export declare namespace Either {
|
|
|
1259
1360
|
/**
|
|
1260
1361
|
* Standalone list predicate
|
|
1261
1362
|
*
|
|
1363
|
+
* @template R underlying value type
|
|
1364
|
+
* @template L underlying error type
|
|
1262
1365
|
* @param eithers a list of Either
|
|
1263
1366
|
* @returns true in case every list element is Left
|
|
1264
1367
|
*/
|
|
@@ -1266,6 +1369,8 @@ export declare namespace Either {
|
|
|
1266
1369
|
/**
|
|
1267
1370
|
* Standalone list predicate
|
|
1268
1371
|
*
|
|
1372
|
+
* @template R underlying value type
|
|
1373
|
+
* @template L underlying error type
|
|
1269
1374
|
* @param eithers a list of Either
|
|
1270
1375
|
* @returns true in case at least one list element is Left
|
|
1271
1376
|
*/
|
|
@@ -1276,6 +1381,7 @@ export declare namespace Either {
|
|
|
1276
1381
|
* Applying yield to an Either within the generator function unwraps the Either and returns underlying value in case of success
|
|
1277
1382
|
* However the convenient option for typescript is to use ```yield* either.generator()``` as otherwise one may have to deal with union types
|
|
1278
1383
|
*
|
|
1384
|
+
* @template T yielded underlying type
|
|
1279
1385
|
* @template TT yielded Either type
|
|
1280
1386
|
* @template R returned underlying type
|
|
1281
1387
|
* @param eitherGeneratorFunction Either generator function
|
|
@@ -1307,6 +1413,7 @@ export type TaskFunction<A extends unknown[], R> = (...args: A) => Task<R>;
|
|
|
1307
1413
|
/**
|
|
1308
1414
|
* Task generator
|
|
1309
1415
|
*
|
|
1416
|
+
* @template T yielded underlying type
|
|
1310
1417
|
* @template TT yielded task type
|
|
1311
1418
|
* @template R returned task resolve type
|
|
1312
1419
|
*
|
|
@@ -1324,6 +1431,7 @@ export type TaskGenerator<T, TT extends Task<T>, R> = Generator<TT, R, T>;
|
|
|
1324
1431
|
* Function returning task generator (generator function)
|
|
1325
1432
|
*
|
|
1326
1433
|
* @template A argument types
|
|
1434
|
+
* @template T yielded underlying type
|
|
1327
1435
|
* @template TT yielded task type
|
|
1328
1436
|
* @template R returned task resolve type
|
|
1329
1437
|
*
|
|
@@ -1457,6 +1565,11 @@ export interface Task<R> extends TaskBase<R> {
|
|
|
1457
1565
|
rejected: (error: any) => Task<R3>;
|
|
1458
1566
|
canceled: () => Task<R4>;
|
|
1459
1567
|
}): Task<R2 | R3 | R4>;
|
|
1568
|
+
/**
|
|
1569
|
+
* Read the settled result when the task has already finished
|
|
1570
|
+
*
|
|
1571
|
+
* @returns settled result, or null when the task is still pending
|
|
1572
|
+
*/
|
|
1460
1573
|
resolved: () => Cancelable<R> | null;
|
|
1461
1574
|
/**
|
|
1462
1575
|
* Return underlying promise in order to await result
|
|
@@ -1465,13 +1578,16 @@ export interface Task<R> extends TaskBase<R> {
|
|
|
1465
1578
|
*/
|
|
1466
1579
|
resolve: () => TaskInvoke<R>;
|
|
1467
1580
|
/**
|
|
1468
|
-
* Invoke underlying
|
|
1581
|
+
* Invoke underlying cancel method without error
|
|
1582
|
+
*
|
|
1583
|
+
* @returns 'true' when the task was still pending and cancelation was applied
|
|
1469
1584
|
*/
|
|
1470
1585
|
cancel: () => boolean;
|
|
1471
1586
|
/**
|
|
1472
|
-
* Invoke underlying
|
|
1587
|
+
* Invoke underlying cancel method with error
|
|
1473
1588
|
*
|
|
1474
1589
|
* @param error error value to be injected from outside
|
|
1590
|
+
* @returns 'true' when the task was still pending and the error was applied
|
|
1475
1591
|
*/
|
|
1476
1592
|
reject: (error: any) => boolean;
|
|
1477
1593
|
/**
|
|
@@ -1531,14 +1647,14 @@ export declare namespace Task {
|
|
|
1531
1647
|
*
|
|
1532
1648
|
* @template R returned task's resolve type
|
|
1533
1649
|
* @param error error to be returned upon awaiting
|
|
1534
|
-
* @returns task
|
|
1650
|
+
* @returns task rejected with the specified error
|
|
1535
1651
|
*/
|
|
1536
1652
|
function rejected<R>(error: any): Task<R>;
|
|
1537
1653
|
/**
|
|
1538
1654
|
* Invariant task constructor creating canceled task
|
|
1539
1655
|
*
|
|
1540
1656
|
* @template R returned task's resolve type
|
|
1541
|
-
* @returns task
|
|
1657
|
+
* @returns canceled task
|
|
1542
1658
|
*/
|
|
1543
1659
|
function canceled<R>(): Task<R>;
|
|
1544
1660
|
/**
|
|
@@ -1587,10 +1703,12 @@ export declare namespace Task {
|
|
|
1587
1703
|
/**
|
|
1588
1704
|
* Generic callback task
|
|
1589
1705
|
*
|
|
1590
|
-
* Usefull for creating custom tasks from success and error callbacks and cancelaton function. Synchronous callbacks are not supported, @see
|
|
1706
|
+
* Usefull for creating custom tasks from success and error callbacks and cancelaton function. Synchronous callbacks are not supported, @see fromFunction
|
|
1591
1707
|
*
|
|
1708
|
+
* @template H cancelation handler type
|
|
1709
|
+
* @template R returned task resolve type
|
|
1592
1710
|
* @param create task body with success and error callbacks
|
|
1593
|
-
* @param
|
|
1711
|
+
* @param onCancel cancelation function intended for stopping task execution
|
|
1594
1712
|
* @returns task resolving to success value
|
|
1595
1713
|
*
|
|
1596
1714
|
* @example
|
|
@@ -1632,9 +1750,8 @@ export declare namespace Task {
|
|
|
1632
1750
|
/**
|
|
1633
1751
|
* Convinience shortcut for yielding timers
|
|
1634
1752
|
*
|
|
1635
|
-
* @
|
|
1636
|
-
* @
|
|
1637
|
-
* @returns generator to be be used with yield*
|
|
1753
|
+
* @param delay duration in ms after that the generator resolves
|
|
1754
|
+
* @returns generator to be used with yield*
|
|
1638
1755
|
*/
|
|
1639
1756
|
function timeoutGenerator(delay: number): TaskGenerator<unknown, Task<void>, void>;
|
|
1640
1757
|
/**
|
|
@@ -1666,6 +1783,7 @@ export declare namespace Task {
|
|
|
1666
1783
|
*
|
|
1667
1784
|
* If error is not caught the task is interrupted and returns 'just left error' immediately. In case of cancelation the task is interrupted and returns 'nothing' immediately
|
|
1668
1785
|
*
|
|
1786
|
+
* @template T yielded underlying type
|
|
1669
1787
|
* @template TT yielded task type
|
|
1670
1788
|
* @template R returned task resolve type
|
|
1671
1789
|
* @param taskGeneratorFunction task generator function
|
|
@@ -1695,11 +1813,12 @@ export declare namespace Task {
|
|
|
1695
1813
|
*
|
|
1696
1814
|
* Simplifies wrighting functions returning generated tasks
|
|
1697
1815
|
*
|
|
1698
|
-
* @template
|
|
1816
|
+
* @template A generator arguments
|
|
1817
|
+
* @template T yielded underlying type
|
|
1699
1818
|
* @template TT yielded task type
|
|
1700
1819
|
* @template R returned task resolve type
|
|
1701
1820
|
* @param taskGeneratorFunction function* (...args) task generator function
|
|
1702
|
-
* @returns task resolving to generator's return type
|
|
1821
|
+
* @returns task function resolving to generator's return type
|
|
1703
1822
|
*/
|
|
1704
1823
|
function generateFunction<A extends any[], T, TT extends Task<T>, R>(taskGeneratorFunction: TaskGeneratorFunction<A, T, TT, R>): TaskFunction<A, R>;
|
|
1705
1824
|
/**
|
|
@@ -1723,6 +1842,7 @@ export declare namespace Task {
|
|
|
1723
1842
|
/**
|
|
1724
1843
|
* Start multiple tasks one after another
|
|
1725
1844
|
*
|
|
1845
|
+
* @template T underlying task type
|
|
1726
1846
|
* @param taskFunctions list of task functions (without arguments)
|
|
1727
1847
|
* @returns composite task invoring every task in order and resolving to the list of results
|
|
1728
1848
|
*/
|
|
@@ -1738,7 +1858,7 @@ export declare namespace Task {
|
|
|
1738
1858
|
*
|
|
1739
1859
|
* @template T underlying task type
|
|
1740
1860
|
* @param tasks iterable of tasks to execute
|
|
1741
|
-
* @
|
|
1861
|
+
* @returns task resolving to the list of results
|
|
1742
1862
|
*/
|
|
1743
1863
|
function all<T>(tasks: Iterable<Task<T>>): Task<T[]>;
|
|
1744
1864
|
/**
|
|
@@ -1753,7 +1873,7 @@ export declare namespace Task {
|
|
|
1753
1873
|
*
|
|
1754
1874
|
* @template T underlying task type
|
|
1755
1875
|
* @param tasks iterable of tasks to execute
|
|
1756
|
-
* @
|
|
1876
|
+
* @returns task resolving to the result of first successfull task
|
|
1757
1877
|
*/
|
|
1758
1878
|
function any<T>(tasks: Iterable<Task<T>>): Task<unknown>;
|
|
1759
1879
|
/**
|
|
@@ -1762,6 +1882,7 @@ export declare namespace Task {
|
|
|
1762
1882
|
* If the second task resolves sooner than the first, resulting task is canceled
|
|
1763
1883
|
* Otherwise the resulting task resolves together with the first one
|
|
1764
1884
|
*
|
|
1885
|
+
* @template T underlying task type
|
|
1765
1886
|
* @param task task to limit
|
|
1766
1887
|
* @param limitTask limiting task
|
|
1767
1888
|
* @returns task limites according to limitTask
|
|
@@ -1773,7 +1894,9 @@ export declare namespace Task {
|
|
|
1773
1894
|
* Given task is re-generated in case of failure (both external and internal)
|
|
1774
1895
|
* Resulting task is still cancelable by standard means
|
|
1775
1896
|
*
|
|
1897
|
+
* @template T underlying task type
|
|
1776
1898
|
* @param taskFunction task preoducing function
|
|
1899
|
+
* @returns task that retries until the produced task resolves
|
|
1777
1900
|
*/
|
|
1778
1901
|
function repeat<T>(taskFunction: TaskFunction<[], T>): Task<T>;
|
|
1779
1902
|
}
|
package/dist/t-tasks.esm.js
CHANGED
|
@@ -612,29 +612,52 @@ function chainTaskMaybe(parent, op) {
|
|
|
612
612
|
else return false;
|
|
613
613
|
});
|
|
614
614
|
}
|
|
615
|
-
function
|
|
616
|
-
|
|
615
|
+
function mapTaskMaybe(parent, op) {
|
|
616
|
+
const cell = settleCell();
|
|
617
|
+
let state = { phase: "parent" };
|
|
618
|
+
parent._invoke((result) => {
|
|
619
|
+
state = {
|
|
620
|
+
phase: "transform",
|
|
621
|
+
error: null
|
|
622
|
+
};
|
|
623
|
+
let value = null;
|
|
624
|
+
try {
|
|
625
|
+
value = op(result);
|
|
626
|
+
} catch (e) {
|
|
627
|
+
cell.resolve(Maybe.just(Either.left(e)));
|
|
628
|
+
state = { phase: "closed" };
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const transformError = state.phase === "transform" ? state.error : null;
|
|
632
|
+
if (transformError) cell.resolve(transformError.map(Either.left));
|
|
633
|
+
else cell.resolve(value);
|
|
634
|
+
state = { phase: "closed" };
|
|
635
|
+
});
|
|
636
|
+
return Task.create(cell.promise, (error) => {
|
|
637
|
+
if (cell.settled()) return false;
|
|
638
|
+
if (state.phase === "parent") return parent._cancel(error);
|
|
639
|
+
else if (state.phase === "transform") {
|
|
640
|
+
state.error = error;
|
|
641
|
+
return true;
|
|
642
|
+
} else return false;
|
|
643
|
+
});
|
|
617
644
|
}
|
|
618
|
-
function
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
nothing: Task.canceled
|
|
626
|
-
});
|
|
645
|
+
function tapTaskMaybe(parent, op) {
|
|
646
|
+
parent._invoke((result) => {
|
|
647
|
+
try {
|
|
648
|
+
op(result);
|
|
649
|
+
} catch (e) {
|
|
650
|
+
reportError(e);
|
|
651
|
+
}
|
|
627
652
|
});
|
|
653
|
+
return parent;
|
|
654
|
+
}
|
|
655
|
+
function chainTaskEither(_task, op) {
|
|
656
|
+
return chainTaskMaybe(_task, (maybe) => maybe.map(op).orMap(Task.canceled).just);
|
|
628
657
|
}
|
|
629
658
|
function mapTaskEither(_task, op) {
|
|
630
659
|
return mapTaskMaybe(_task, (maybe) => maybe.map(op));
|
|
631
660
|
}
|
|
632
|
-
function tapTaskMaybe(_task, op) {
|
|
633
|
-
return mapTaskMaybe(_task, (value) => {
|
|
634
|
-
op(value);
|
|
635
|
-
return value;
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
661
|
function tapTaskEither(_task, op) {
|
|
639
662
|
return tapTaskMaybe(_task, (maybe) => maybe.tap(op));
|
|
640
663
|
}
|
|
@@ -746,6 +769,9 @@ var TaskClass = class {
|
|
|
746
769
|
});
|
|
747
770
|
}
|
|
748
771
|
};
|
|
772
|
+
function reportError(error) {
|
|
773
|
+
if (typeof globalThis.reportError === "function") globalThis.reportError(error);
|
|
774
|
+
}
|
|
749
775
|
//#endregion
|
|
750
776
|
export { Either, Just, Left, Maybe, Right, Task };
|
|
751
777
|
|