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

The relative future provided by any plugin call is not getting completed. #35

Open
DK070202 opened this issue Jun 5, 2023 · 3 comments · May be fixed by #38
Open

The relative future provided by any plugin call is not getting completed. #35

DK070202 opened this issue Jun 5, 2023 · 3 comments · May be fixed by #38

Comments

@DK070202
Copy link

DK070202 commented Jun 5, 2023

Description:

  • The relative future provided by any plugin call is not getting completed.

Steps to reproduce:

Future<void> triggerCTAEvent() async {
  await WebEngagePlugin.trackEvent('Added to Cart', {
    "CTA": "add_to_cart",
  });

  log('Pushed CTA event to analytics');
}

triggerCTAEvent(); // It won't print the log-in console. 

How it can be fixed:

  • The plugin is not calling success or error.
private void setUserListAttribute(MethodCall call, Result result) {
    String attributeName = call.argument(ATTRIBUTE_NAME);
    List<? extends Object> attributes = call.argument(ATTRIBUTES);
    WebEngage.get().user().setAttribute(attributeName, attributes);
}
  • After the call of WebEngage, call the success or error method relatively at the end of the callback.
  • example:
private void setUserListAttribute(MethodCall call, Result result) {
    String attributeName = call.argument(ATTRIBUTE_NAME);
    List<? extends Object> attributes = call.argument(ATTRIBUTES);
    WebEngage.get().user().setAttribute(attributeName, attributes);
    result.success(null);  // <-- Add this line at the end of all call from the flutter or dart side 
}
  • Now from the flutter side:
triggerCTAEvent(); // It will log this: `Pushed CTA event to analytics`. 
@DK070202
Copy link
Author

DK070202 commented Jun 5, 2023

Request Id: 71045

@MilindWebEngage
Copy link
Collaborator

Thank you, @DK070202 , for reporting this issue.
This is a known issue, and according to our documentation, we advise clients not to use the "await" keyword in any syntax of our code, as it does not return anything.

When we redevelop our plugin in Flutter in Future, we will be removing the "Future" declaration, and it will simply be "void." Therefore, please call the method without the "await" keyword.

@DK070202
Copy link
Author

DK070202 commented Jun 5, 2023

Thank you, @DK070202 , for reporting this issue. This is a known issue, and according to our documentation, we advise clients not to use the "await" keyword in any syntax of our code, as it does not return anything.

When we redevelop our plugin in Flutter in Future, we will be removing the "Future" declaration, and it will simply be "void." Therefore, please call the method without the "await" keyword.

But behind the scenes, actual implementation will definitely be async that's how Flutter has API for method channels. And at my sight the are no advantages to hiding async implementation but there are certain disadvantages of it.

Apart from that not completing the method call is the main concern here. It may lead the app to undefined memory behaviors and that call (method channel) would still buffer as they haven't been marked as either completed or failed.

This may also lead to the un-order event in some edge cases:

 doCreateOrder();  //--> App logic
 sendCreateOrder(); //--> An event with some heavy payload.
 doPayment(); //--> App logic
 sendPaymentCompletionEvent(); //-->An event with minimal payload. 

Here in this case sendPaymentCompletionEvent may called first and sendCheckoutEvent may be called after it as we don’t have async - await working here properly. Also, the method defined in the SDK returns future and if somehow one adds the await before sendCheckoutEvent then doPayment won’t be completed any time in the future.

And it would be great if you share an explanation to remove futures.

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

Successfully merging a pull request may close this issue.

2 participants