Skip to content
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

Don't provide a service when the getter throws an error #39

Merged
merged 1 commit into from
Dec 3, 2015
Merged

Don't provide a service when the getter throws an error #39

merged 1 commit into from
Dec 3, 2015

Conversation

rdallasgray
Copy link
Contributor

In the case where I have an external service which may not be ready (say it has to be loaded asynchronously), I want to throw an error:

bottle.factory("asyncService", function(container) {
    var service = window.asyncService;
    if (service === undefined) {
        throw new Error("Service is not loaded");
    }
    return service;
}

The present behaviour, on getting container.asyncService will throw the error once, and then afterwards return undefined. Even if the service resolves at some point, the result of container.asyncService will always be undefined after the initial call.

This changes the behaviour so as to throw the error until the service resolves, and then behave as before. The use case is that I have services dependent on another service which is not ready until after bottle.resolve() has been called. I want to fail fast if anything tries to access that service before then.

It's a super-simple change in the code which just involves changing the order of when property names are deleted from the container vs when $get is called.

@rdallasgray
Copy link
Contributor Author

young-steveo added a commit that referenced this pull request Dec 3, 2015
Don't provide a service when the getter throws an error
@young-steveo young-steveo merged commit 7fba985 into young-steveo:master Dec 3, 2015
@young-steveo
Copy link
Owner

This is now in release 1.2.1

@rdallasgray
Copy link
Contributor Author

Hey, that's great Steven, many thanks.

Have a good Christmas and New Year!

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

Successfully merging this pull request may close these issues.

2 participants