loomnetwork / unity-sdk

Loom DAppChain SDK for Unity3d
Other
121 stars 34 forks source link

Added IRpcClient.ConnectAsync method #41

Closed ZimM-LostPolygon closed 6 years ago

ZimM-LostPolygon commented 6 years ago

Previously, whenever connection was lost for whatever reason (Internet connection loss, IRpcClient.DisconnectAsync), there was to no way to explicitly reconnect without doing anything else. Instead, whenever CallAsync or StaticCallAsync was called when disconnected, RpcClients would just attempt to silently reconnect. This is not ideal for a few reasons: 1) It might be required to reconnect without immediately sending any data. 2) This behavior hides the "truth" and is different from the usual behavior of socket-like entities. If connection is lost, I would expect CallAsync to throw an exception immediately, instead of silently attempting to reconnect.

This PR solves point 1 by adding a IRpcClient.ConnectAsync method.

ZimM-LostPolygon commented 6 years ago

@enlight Did some changes. Basically: if both clients were provided to the constructor, auto-reconnect will ensure both clients are connected before doing any communication. If only read client was passed (as in the cases you described), write client will be ignored. Also added an AutoReconnect property that controls this behavior and made added better exceptions for cases when client is null.

enlight commented 6 years ago

LGTM, thank you :)