-
Notifications
You must be signed in to change notification settings - Fork 165
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
Proposal: replace callbacks by Promises #74
Comments
Hey Chnapy. I think it's a good idea. This library was written before Promises were standardized in JavaScript. Introducing native promises would be a breaking change. So I think it should be introduced as part of 1.x.x. I am open to hearing proposals about how the API would be affected by this change. One thing that comes to mind. Currently |
Hi ! Thanks for your answer, I see the 'cancel' problematic. The first one export interface PathObject {
promise: Promise<Position[]>; // Position = {x,y}
cancel: () => boolean;
} So The second one var instances: {
[id: number]: Instance;
}; My suggestion is to instead use a var instances: Map<Promise, Instance>; So now we can do this: finder.findPath(startX, startY, endX, endY);
const promises = finder.calculate();
// On first path done, do something
promises[0].then(path => console.log(path));
// I want to cancel the first path
finder.cancelPath(promises[0]) I cancel the path calculation by simply giving the promise itself. I like this solution, it keeps the initial logic, and I find it quite elegant. But the type change of |
A better option might be to dynamically add a |
Hi,
I was wondering if there is any reason Easystar should not use
Promise
objects. My idea is that instead of usingcallback
s given tofindPath()
, the functioncalculate()
would simply return an array ofPromise
(one for each path).The only concern I see is the ES6 requirement, but Babel is here for that.
Promises are used today in a lot of libs and apps, they are normalized and quite easy to use. In my app I wrap the callback in a Promise, what is not very elegant.
I can do a PR, I just want some returns before digging the code.
What do you think ?
The text was updated successfully, but these errors were encountered: