-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Make all async functions return a Future #31
Comments
@synw hello, the reason is that there are streams with events which can happen many times during client lifetime. For example But you can also want to do some work as soon as connection established (write sth to a screen). But suppose you also need to do this work after each reconnect. In this case you also register your work in connectStream handler. In this case you need a way to only do your work once. In general we can solve this by adding I don't have strong opinion here, maybe you can describe an API you want with some examples and use cases? With understanding that events like |
Ok. The non awaitable Please notice that an async function returning void is non idiomatic in Dart: there is a linting rule about this. Btw I would recommend using more strict analysis options for this package. Pedantic is quite standard now as used by Google and for pub.dev packages evaluation (pana). I personally use and highly recommend Extra Pedantic, which is very strict. You already use |
@synw thanks for suggestions. Since I maintain all Centrifuge libs and Dart is not my day to day language I hardly can find time and knowledge to refactor for idiomatic code. If you are using this library then maybe you can send pr with all your code style recommendations - will be happy to accept. |
+ fixed centrifugal#31
I was looking for an await connection / await subscription, too.
Let's say due to the delay of connection, I call the API endpoint first. I receive Now my value remains true but in the backend it already changed to false. I know that there are some ways to solve the issue as example working with history and receiving the last messages from the channel, however, I believe that this is not optimal. |
I tried to explain why connect and subscribe are not awaitable in #31 (comment). Again - the main concern about making connect and subscribe awaitable is that during connection lifetime onConnect and onSubscribe events can happen multiple times (due to network disconnects). Not sure what's the use case when you only need to do some onConnect work only once, but not need to do it after reconnect - i.e. when onConnect will happen second time. Having onConnect theoretically allows to implement a Future on top of this library. But just not understand why this can be useful due to concerns above. |
So what is a proper way to manage connection state on client? Sometimes app is in background and disconnected by server side, in this case disconnectStream listener wont handle disconnect event and a i can't use isConnected flag for check connection state. How should i call connect again? What is proper way to subscribe channels initial? Im trying to subscribe on connect event in connectStream, but onSubscribe events happens multiple times, and each time subscribe recalls as result i have trash in subscriptions. What is proper way to resubscribe channels on reconnect? |
@pashtetbezd hi, your question is off topic here. Try asking in community rooms. General answer - you better not use websockets in background - you should disconnect and use push notifications for important messages. |
I wanted to say that if the function returned futures there would be no question caused streams hell. Please add the futures. |
@pashtetbezd could you show what you mean on example? Also, how adding futures addresses concerns mentioned in #31 (comment) ? |
Addressed by v0.8.0 |
Would it be possible to return a future for all async methods? I have noticed that some async methods return
void
and notFuture<void>
which make then non awaitable. Is this on purpose?Ex: I would like to await
connect
but can't because it does not return a future:Here
_connect
returns a future, andconnect
would be great this way:Is it possible or the actual way is by design?
The text was updated successfully, but these errors were encountered: