question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Synchronicity issues

See original GitHub issue

Since the nature of our framework is asynchronous we need to provide ways to handle that situation.

Example

The user changes the cartocss of a layer and he wants to draw a red dot when there was an error. With the current api we got:

layer.setStyle(newStyle);
// layer fires  a ' styleChanged'  event without knowing the server's response

So the only way of detect an error would be through the client error api: Notice this is not yet implemented and currently a cartoError has only a message field

client.on(carto.events.ERROR, function(cartoError) { 
  switch(cartoError.type) {
    case: 'layerError': 
     // ...
    break;
    ...
});

// If some error happened will be detected by the client error callback
layer.setStyle(newStyle);

Options

Since callbacks are being deprecated and we must to change the API I bet for using promises and events resulting in a very powerful api.

layer.setStyle(newStyle)
  .then(nextFunction) // This callback will be executed once the style is set 
  .catch(errorFunciton) // This callback will be executed if there was some errors

layer.on('error', callback); // The layer will also trigger errors
layer.on('success', callback); // Should we have a `success` event too?

This also alows using the async/await feature introduced in ES6.

try {
  await  layer.setStyle(newStyle); 
  await  layer.setSource(newSource); // This method waits the style to be changed!
catch(cartoError) {
  errorFun(cartoError);
}

This is very useful to prevent unnecessary map reloads, think about an application where the user sets multiple changes into the map.

You could enqueue those changes and reload them at a stroke.

// This changes are not sent to the server
layer.setStyle(newStyle, {reload: false}); 
layer.setSource(newSource, {reload: false}); 
layer.setFeatureOverColumns(['foo'], {reload: false}); 
// Reload the map, once is reloaded show a popup, show widgets...etc
layer.reload()
  .then(() => popup('Reload ok!');
  .catch(cartoError => popup(cartoError.message); // Notice each layer/dataview will also throw its cartoErrors

Current status

We got a POC where the layer.setStyle and layer.setSource methods where updated There is also a working example for updating layer styles.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Jesus89commented, Nov 23, 2017

I think Promises are a nice way for the programmer to manage async operations. For example detecting success/error on a particular function or concatenate async methods.

Events are fine too, in order to detect changes without taking to account where the change happens, like in the dataviews’ dataChange event for example.

So I think both approaches have advantages and they have complementary functionality so I would include both.

0reactions
IagoLastcommented, Nov 24, 2017

Using promises should be optional IMO

Is optional, but the browsers warns about an possible uncaught error, not sure if we can prevent it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Synchrony Bank down? Current outages and problems
Real-time problems and outages for Synchrony Bank. Is the site down? Login not working? Here you see what is going on.
Read more >
Synchronicity - an overview | ScienceDirect Topics
Again, synchronicity is an issue: The more roles that are changing simultaneously, the more the stress is compounded.
Read more >
When Is an Overload of Synchronicities Not Psychosis?
Key questions begin with making an appropriate diagnosis (schizophrenia, bipolar disorder, or drug-induced psychosis). People who write about ...
Read more >
Synchrony | Complaints | Better Business Bureau® Profile
Initial Complaint. 12/19/2022. Complaint Type: Problems with Product/Service. Status: Resolved.
Read more >
Coincidences: What causes them? - CNN
Synchronicity is an odd term, but it's a familiar experience to many ... by people looking for answers to personal problems, says Williams, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found