-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
Proper way to wait until prepare is done #152
Comments
What happens if you try to prepare with |
The point is that I want my class to be a manager of all things related to IAP in my app. and it should be initialized when the app launches. I want to use it in another component aswell, so I don't think putting the Can I call |
Perhaps a mutex could be used to solve this issue? I'm thinking that the mutex would be locked in the beginning of the |
@axelkennedal You can use |
But what if I use the library in two components that load at the same time? Isn't it highly likely then that |
@axelkennedal You need your programming skill to solve this kind of problem currently. If I were you, I would set one global variable that manages if you've called
Hope it helps you. |
Yeah, that might be the beginning of a solution, but I think it needs to be paired with a mutex, otherwise there is still the chance that both components call |
@axelkennedal |
The way that you describe it there are two possible ways of interpreting it.
OR
For interpretation 1 this is possible to happen (c1 is a component and c2 is another component): And for interpretation 2 this can happen: And I'm sure there are more ways it can fail. It seems to me that your approach is too naive and doesn't work in all cases. When you have two components that load at the same time and try to interact with the library at the same time these things do happen (as I've seen when experimenting with it). |
Here is a slightly more sophisticated solution, which handles the above sort of cases. I've tested it and it seems to work as intended. What's the best way to structure the usage of
|
@axelkennedal I exactly agree with what you've described above. I just posted the starter solution for your problem. It could be improved, like when you call |
I'm happy to hear you agree 😄 Yes, this should for sure be handled on the native side 👍 |
@axelkennedal I've released |
I'm not sure I understand what you mean. Are you telling me that the other functions of the library will now wait until |
@axelkennedal I've just blocked from starting new billing client in android when |
@dooboolab do you know of any disadvantages of calling |
@nico1510 Since billing service is running all the time, basically your application will assign another thread that lives all the time which is useless. Also, there maybe some defects in handling background service running in your app. It will be much safe to let go when you don't need that background service to be running. |
@dooboolab thanks I'll follow your advice :) |
Version of react-native-iap
0.3.23
Platforms you faced the problem (IOS or Android or both?)
Android
Problem
Some methods of this library are getting called before
prepare()
is done.Description
I'm wondering what the recommended way is for waiting until the library is ready to process requests on Android. The example provided in the README cannot really be applied directly to my application, since what I'm doing is I've created a class with
static
functions for handling In App Purchases (kind of an abstraction on top of this library). In myApp.js
I callprepare()
incomponentDidMount()
, and so the issue is that the other component of my app will load and callgetProducts(itemSKUs)
beforecomponentDidMount()
(and therewithprepare()
) is done executing.My current (not very pleasing) solution is to just set a timeout of 1 second in the other component before calling
getProducts(itemSKUs)
from it.I had an idea about setting a boolean like this and then making it so that the other functions have to wait for it to be true before they can execute, but I'm not sure how to accomplish that.
The text was updated successfully, but these errors were encountered: