@@ -103,15 +103,29 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
103
103
104
104
/// {@category execution}
105
105
Future <R > runFuture (E env) async {
106
- final result = await _unsafeRun (env);
107
- return switch (result) {
106
+ final result = _unsafeRun (env);
107
+ if (result is ! Future ) {
108
+ print (
109
+ "You can use runSync instead of runFuture since the Effect is synchronous" ,
110
+ );
111
+ }
112
+
113
+ return switch (await result) {
108
114
Left (value: final cause) => throw cause,
109
115
Right (value: final value) => value,
110
116
};
111
117
}
112
118
113
119
/// {@category execution}
114
- Future <Exit <L , R >> runFutureExit (E env) async => _unsafeRun (env);
120
+ Future <Exit <L , R >> runFutureExit (E env) async {
121
+ final result = _unsafeRun (env);
122
+ if (result is ! Future ) {
123
+ print (
124
+ "You can use runSyncExit instead of runFutureExit since the Effect is synchronous" ,
125
+ );
126
+ }
127
+ return result;
128
+ }
115
129
116
130
/// {@category constructors}
117
131
factory Effect .gen (DoFunctionEffect <E , L , R > f) => Effect <E , L , R >._(
@@ -366,8 +380,8 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
366
380
);
367
381
368
382
/// {@category error_handling}
369
- Effect <E , Never , R > catchError (
370
- Effect <E , Never , R > Function (L error) f,
383
+ Effect <E , C , R > catchError < C > (
384
+ Effect <E , C , R > Function (L error) f,
371
385
) =>
372
386
Effect ._(
373
387
(env) => _unsafeRun (env).then (
@@ -382,6 +396,20 @@ final class Effect<E, L, R> extends IEffect<E, L, R> {
382
396
},
383
397
),
384
398
);
399
+
400
+ /// {@category error_handling}
401
+ Effect <E , C , R > catchCause <C >(
402
+ Effect <E , C , R > Function (Cause <L > cause) f,
403
+ ) =>
404
+ Effect ._(
405
+ (env) => _unsafeRun (env).then (
406
+ (exit) => switch (exit) {
407
+ Left (value: final cause) => f (cause),
408
+ Right (value: final value) => Effect <E , C , R >.succeed (value),
409
+ }
410
+ ._unsafeRun (env),
411
+ ),
412
+ );
385
413
}
386
414
387
415
extension ProvideNever <L , R > on Effect <Never , L , R > {
0 commit comments