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

await for getClusterLeaves #9739

Closed
transfluxus opened this issue May 29, 2020 · 3 comments
Closed

await for getClusterLeaves #9739

transfluxus opened this issue May 29, 2020 · 3 comments

Comments

@transfluxus
Copy link

Motivation

basically described here:
#8613

I want to run over a bunch of clusters make some calculation over their leaves and then set the data of a source. Having a callback in the middle for all clusters makes the whole procedure hard

Design Alternatives

have an await for getClusterLeaves

Design

getClusterLeaves with Promise a basically because Callbacks should be dead

Mock-Up

source_layer.getClusterLeaves(cluster_id, cluster.properties.point_count, 0).then(leaves => {}).catch(err => {}) ....

leaves = await source_layer.getClusterLeaves(cluster_id, cluster.properties.point_count, 0)

Concepts

Promises, many JS developer know promises by now

@mourner
Copy link
Member

mourner commented May 29, 2020

Duplicate of #3964

@mourner mourner marked this as a duplicate of #3964 May 29, 2020
@mourner mourner closed this as completed May 29, 2020
@hmendezm
Copy link

hmendezm commented Nov 4, 2020

I am not able to await getClusterleaves. Can someone give an example of how I can wait for the getClusterLeaves? I need to have the leaves before continue running the next code

await clusterSource.getClusterLeaves(clusterId, total, 0, function (err, aFeatures) {
that._clusterLeaves = aFeatures;
});
console.log(that._clusterLeaves );

@vchrisb
Copy link

vchrisb commented Jun 30, 2021

In my case I created a vue method to wrap the callback based function with a Promise:

getClusterLeaves(cluster_id, limit, offset) {
  return new Promise((resolve, reject) => {
    this.map.getSource('locations').getClusterLeaves(cluster_id, limit, offset, (err, features) => {
      if (err) reject(err);
      else resolve(features);
    });
  });
};

this could then be used by:

await this.getClusterLeaves(feature.properties.cluster_id, feature.properties.point_count, 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants