Skip to content
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

An asynchronous start() problem #50

Open
theJiawen opened this issue Nov 26, 2018 · 1 comment
Open

An asynchronous start() problem #50

theJiawen opened this issue Nov 26, 2018 · 1 comment
Assignees
Milestone

Comments

@theJiawen
Copy link

theJiawen commented Nov 26, 2018

I notice that measureTool.start(initialPoints) method is asynchronous, which means that If I write code like this:

// say, there are 10 points in array `initialPoints`, with total length 1000m
measureTool.start(initialPoints);
console.log(measureTool.length);  // 0

I will not get what I want.

Can you make start() return a promise ?
like this:

measureTool.start(initialPoints).then ((tool)=>{ console.log(tool.length) })
@zhenyanghua
Copy link
Owner

zhenyanghua commented Dec 4, 2018

Sorry for the delay. I don't want to introduce another polyfill for promise yet as this tool targets IE11 as well while I want to minimize the codebase and dependencies. At this moment, I should update the documentation to indicate the method is asynchronous. Because all measurement events are event-driven, event listeners must be used to guarantee obtaining the last result. You should be able to get the measurement by listening to the 'measure_change' event at this moment. I will leave this issue open and work out a solution. This will likely force the API signature to change, so it will be in the next major version.

@zhenyanghua zhenyanghua self-assigned this Dec 4, 2018
@zhenyanghua zhenyanghua added this to the v1.0.0 milestone Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants