-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Best design pattern for starting only one async operation and share signal result #828
Comments
You can use |
But still I had to use this instnace variable to hold replayed signal while async work is being done? |
I'm not entirely sure I understand your question. You may want to check out my example of fetching an authentication token before API calls, since it uses a similar pattern. |
Well may be I've provided a wrong description. While the async operation is running because of the first subscription, I want any other subscription to share the result, but when this work is done and signal completes, I want any new subscription to start this work again. Sorry for my english ;) |
In that case, I'm not sure there's a significantly better approach than what you've done. However, there are some things to note:
|
Great! Thank you so much Justin! How could I miss |
✨ |
If you don't want to use methods, instance variables, or properties, you could try something like this:
Using an array or subject, you can keep a reference to something without declaring a variable or using a property. |
That code isn't thread safe. Sometimes using a variable really is the best answer. |
Ok...so it sounds like the safest strategy is to use atomic properties as "anchors", especially for any variables that you weave in and out of RAC blocks. |
I'm facing a kind of same issue with a shared signal that I won't to "re-trigger" when it's needed. More in detail:
My I can I prevent this behaviour? I would like to share the last sent value from my |
Let's pretend that RACSignal *updateSignal encapsulates some async task. When subscription occurs I want every new subscription during the async task to receive same result as the first subscriber.
Right now my code looks like this:
It works but I don't really like how it looks. Do I miss something important here?
The text was updated successfully, but these errors were encountered: