Comments (3)
Unfortunately I think this is unavoidable with the Promise pattern. Potentially you could reduce GC allocations by using predefined methods instead of anonymous methods for your promise callbacks, although as the article you linked mentioned, the method references will be allocated on the heap.
Completely avoiding GC allocations was never a design goal of this library. A typical use-case for this would be to do something like download some data from a web request or asynchronously write a file to disk, in which case your bottleneck will pretty much always be IO. For tasks that run every frame, promises probably aren't the best pattern to use.
from c-sharp-promise.
http://www.what-could-possibly-go-wrong.com/promises-for-game-development/
I found your library because this article mentioned its usage in loading game assets. So I was wondering if it's applicable for loading game assets dynamically. Yes, I agree with you that completely avoiding GC allocation is impossible. Just for some low-level devices, for example, memory below to 1G bytes, the developer has to deal with GC carefully.
By the way, I do not quite get the point that every time the calling of Then() or Done(), there will be a new Promise allocated for the return value. Why should not just use the origin Promise object? It's already designed to store the handlers as Lists, right? From what I understand, Then and Done are just elegant ways to register callbacks. But I don't see the reason that we should register them in different Promises. They are all for the first promise in fact, aren't they?
from c-sharp-promise.
It is necessary to return a new promise every time you call Then()
because it's possible to assign multiple callbacks to the same promise:
// In this example, the text "Callback 1" and "Callback 2" will both be printed as soon as
// the promise returned by Fetch resolves.
var w = Fetch("https://github.com");
w.Then(() => Console.WriteLine("Callback 1"));
w.Then(() => Console.WriteLine("Callback 2"));
// Note that it would be possible to chain different things to the promises returned by the
// two invocations of Then.
In the case of asset loading, I probably wouldn't be too concerned about the garbage allocated by a promise because it will most likely be negligible compared to the memory allocated for the assets themselves, although depending on your use-case your mileage may vary.
from c-sharp-promise.
Related Issues (20)
- Feature Request: Promise retry HOT 2
- How to exit from then when check some conditions HOT 6
- Not Usable inside Tasks? HOT 3
- NuGet Package outdated since last improvements
- Cancelling a promise. HOT 1
- Default and custom error handler HOT 1
- OpenUPM support. Unity Package Manager HOT 3
- A unsolved ambiguous compile error
- Compile Errors in Unity 2020.2.6f1 HOT 1
- For a complete noob... how and what do I import to my Unity project to start using this? HOT 1
- Different results for javascript.Promise and C-Sharp-Promise HOT 2
- Support .NET Standard and 3.5 into the same Unity project HOT 1
- Some general questions about handling promises HOT 3
- Promises are not Serializable HOT 1
- Need implicit casts between Promise<object> and Promise and interfaces HOT 3
- Catch from a Promise<object> returns IPromise instead of IPromise<object> HOT 2
- Promise Queue? HOT 2
- How can I get response data at the first stage HOT 7
- Create an Unity Package of this library HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c-sharp-promise.