Skip to content

allReady never ready since 5.0.4 #150

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

Closed
jsevellec opened this issue Jan 18, 2021 · 9 comments
Closed

allReady never ready since 5.0.4 #150

jsevellec opened this issue Jan 18, 2021 · 9 comments

Comments

@jsevellec
Copy link

Hi,

First of all, thanks for this really good library. It's really useful in my project.

I've got an regression since the version 5.0.4 which was ok in the 5.0.3.

Basically I'm registering a first async singleton object which is needed for 2 others async singleton objects from the same class that i'm registering with 2 different names. I'm then using then getIt.allReady to wait until all objects are available.

The problem in the 5.0.4 is that calling allready never complete.

Here is a simplified test case of my problem that shows the issue :
the test case is working ok on 5.0.3 but fail in 5.0.4 :

import 'package:get_it/get_it.dart';
import 'package:test/test.dart';

class Father {}

class Child {
  final Father father = GetIt.instance.get<Father>();
}

void main() {
  setUp(() async {
    await GetIt.I.reset();
  });

  test('async issue', () async {
    final getIt = GetIt.instance;

    getIt.registerSingletonAsync<Father>(() => Future.value(Father()));

    getIt.registerSingletonAsync<Child>(() => Future.value(Child()),
        instanceName: "childOne", dependsOn: [Father]);

    getIt.registerSingletonAsync<Child>(() => Future.value(Child()),
        instanceName: "childTwo", dependsOn: [Father]);

    await getIt.allReady(timeout: Duration(seconds: 10));

    print("never ready in 5.0.4");
  });
}

I've since that there's a bunch of changes in the commits between the 5.0.3 and the 5.0.4 which are related to that.

Am I doing something wrong? Is there an alternative?

Let me know if you need anything else so i can help to resolve this issue

Cheers

Jérémy

@escamoteur
Copy link
Collaborator

Hi Jérémy,

I just had a look at it and there is definitely a bug but that leads to an exception for me and not that allReady isn't coming back.

Can you confirm that it doesn't come back?

@jsevellec
Copy link
Author

Hi @escamoteur

Yes there's an exception because I've set a timeout on allReady.

If you remove the timeout on the test

// await getIt.allReady(timeout: Duration(seconds: 10));
    await getIt.allReady();

allReady never completes. And it's basically what is happening in my app

@escamoteur
Copy link
Collaborator

That is pretty weird because I can't reproduce that one here. There is a bug in 5.0.4 that throws a 'Father' is not registered error, which I can understand, but the not coming back I don't understand.

@escamoteur
Copy link
Collaborator

I just pushed my new version to github, could you try with a reference to the github repo?

@jsevellec
Copy link
Author

Hum that's weird.

Sure thing. I'll do it right now

@jsevellec
Copy link
Author

I've tried with your last fix from github and allReady now complete.

It's also working in the context of my app

@escamoteur
Copy link
Collaborator

ah good then I will push a new version

@jsevellec
Copy link
Author

perfect thanks!

@escamoteur
Copy link
Collaborator

fixed in V5.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants