Skip to content

Commit 6b327bf

Browse files
authored
Merge pull request #185 from kmartins/dispose
improves disposal function used in resetLazySingleton and unregister Thanks a lot!!
2 parents 4bc79ce + 0b01cf0 commit 6b327bf

File tree

2 files changed

+771
-557
lines changed

2 files changed

+771
-557
lines changed

lib/get_it_impl.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,15 @@ class _GetItImplementation implements GetIt {
10011001

10021002
if (factoryToRemove.instance != null) {
10031003
if (disposingFunction != null) {
1004-
await disposingFunction.call(factoryToRemove.instance as T);
1004+
final dispose = disposingFunction.call(factoryToRemove.instance as T);
1005+
if (dispose is Future) {
1006+
await dispose;
1007+
}
10051008
} else {
1006-
await factoryToRemove.dispose();
1009+
final dispose = factoryToRemove.dispose();
1010+
if (dispose is Future) {
1011+
await dispose;
1012+
}
10071013
}
10081014
}
10091015
}
@@ -1036,9 +1042,15 @@ class _GetItImplementation implements GetIt {
10361042

10371043
if (instanceFactory.instance != null) {
10381044
if (disposingFunction != null) {
1039-
await disposingFunction.call(instanceFactory.instance as T);
1045+
final dispose = disposingFunction.call(instanceFactory.instance as T);
1046+
if (dispose is Future) {
1047+
await dispose;
1048+
}
10401049
} else {
1041-
await instanceFactory.dispose();
1050+
final dispose = instanceFactory.dispose();
1051+
if (dispose is Future) {
1052+
await dispose;
1053+
}
10421054
}
10431055
}
10441056

0 commit comments

Comments
 (0)