-
-
Notifications
You must be signed in to change notification settings - Fork 153
async dispose not work #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Have you put a breakpoint in your test and checked what the get returns?
Am 12. Feb. 2022, 18:00 +0100 schrieb yang-lile ***@***.***>:
… example code:
import 'package:get_it/get_it.dart';
import 'package:test/test.dart';
class ClassName {
Future<ClassName> init() async {
await Future.delayed(Duration.zero);
return this;
}
}
Future<void> main() async {
GetIt.I.registerSingletonAsync<ClassName>(
() => ClassName().init(),
dispose: (param) async {
await Future.delayed(Duration.zero);
print('object');
},
);
// group('getit test', () {
// test('get I', () async {
// await GetIt.I.isReady<ClassName>();
// var className = GetIt.I.get<ClassName>();
// expect(className is ClassName, true);
// });
// });
await GetIt.I.isReady<ClassName>();
var className = GetIt.I.get<ClassName>();
}
expect: terminal output object
actual: nothing output.
How should I do pls!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I try it, but I can't find function of dispose called. it quit immediately. I learn from the scope_test.dart, maybe I need called |
Put the breakpoint directly on your expect statement and check what you got returned
Am 12. Feb. 2022, 18:51 +0100 schrieb yang-lile ***@***.***>:
… I try it, but I can't find function of dispose called. it quit immediately. I learn from the scope_test.dart, maybe I need called await GetIt.I.resetScope(); to let it dispose.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.Message ID: ***@***.***>
|
I know How to call the dispose method: import 'package:get_it/get_it.dart';
import 'package:test/test.dart';
class ClassName {
int count = 0;
dispose() {
count++;
}
}
Future<void> main() async {
GetIt.I.registerSingleton<ClassName>(
ClassName(),
dispose: (param) async {
await Future.delayed(Duration.zero);
param.dispose();
},
);
group('getit test', () {
test('get I', () async {
var className = GetIt.I.get<ClassName>();
expect(className.count, 0);
await GetIt.I.unregister<ClassName>();
expect(className.count, 1);
});
});
} unregister it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example code:
expect: terminal output
object
actual: nothing output.
How should I do pls!
The text was updated successfully, but these errors were encountered: