Real-Serious-Games / C-Sharp-Promise

Promises library for C# for management of asynchronous operations.
MIT License
1.19k stars 149 forks source link

Promises are not Serializable #92

Closed alexvasiu closed 5 years ago

alexvasiu commented 5 years ago

If I want to transmit a promise from server to client using Object Serialization with BinaryFormatter, it will throw an exception because Promise class don't have attribute [Serializable]

Error:

Type 'RSG.Promise`1[[System.Boolean, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' in Assembly 'RSG.Promise, Version=3.0.1.0, Culture=neutral, PublicKeyToken=7019fe0722eef3a4' is not marked as serializable.
RoryDungan commented 5 years ago

I'm not sure why you would want to serialise a promise and send it across the network. A more common use-case would be to use a promise on the client-side to manage an asynchronous request to the server and resolve the promise with the raw data from the server once you receive it. This way the actual promise object never needs to be sent around.

You can think of promises as wrapping up a piece of data that is requested asynchronously, but in this case I think it's more beneficial to think of the promise representing the action of requesting the data than the data itself.