Skip to content

Commit

Permalink
test closable Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMaglione committed Apr 3, 2024
1 parent 3ca43b8 commit 26180a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/fpdart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Scope<R> with ScopeMixin {
final R env;
Scope._(this.env, this._closable);

factory Scope.withEnv(R env, [bool closable = false]) =>
factory Scope.withEnv(R env, {bool closable = false}) =>
Scope._(env, closable);

@override
Expand Down
17 changes: 17 additions & 0 deletions packages/fpdart/test/src/effect/effect_scoping_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ void main() {
expect(mutable, 1);
});

test('closable Scope', () async {
final scope = Scope.withEnv(true, closable: true);
var mutable = 0;
final main =
Effect<bool, String, int>.succeed(10).withScope.addFinalizer(
Effect.functionSucceed(() {
mutable += 1;
return unit;
}),
);

await main.provide(Context.env(scope)).runFuture();
expect(mutable, 0);
scope.closeScope<Null, Never>().runSync();
expect(mutable, 1);
});

group('acquireRelease', () {
test('release when successful', () async {
var mutable = 0;
Expand Down

0 comments on commit 26180a7

Please sign in to comment.