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

th/no-gasyncresult #227

Closed
wants to merge 6 commits into from
Closed

th/no-gasyncresult #227

wants to merge 6 commits into from

Conversation

thom311
Copy link
Member

@thom311 thom311 commented Oct 11, 2018

I think the GAsyncResult pattern is less than optimal.

Maybe it serves a purpose in public glib API, where it better works for language bindings/introspection. For NetworkManager core, it's just a nuisance.

It results in

  • more lines of code (look at the patch)
  • more indirection of calling layers of code
  • less control of what actually happens because of the additional layers of code
  • less type-safety (instead of directly having a callback with suitable arguments, there is a GAsyncReadyCallback. Also, g_simple_async_result_set_op_res_gpointer() etc. looses type information).
  • more resource overhead (GAsyncResult is itself a GObject, ref-counted and unnecessary "features". In most cases, we need a simple heap allocation to package the user-data and relevant state. nm_utils_user_data_pack() is enough).

@thom311
Copy link
Member Author

thom311 commented Oct 11, 2018

there are quite some FIXME comments. I may address them still in this branch...

@lkundrak lkundrak force-pushed the th/no-gasyncresult branch 2 times, most recently from 95c4dd0 to b53c35f Compare October 11, 2018 10:48
@lkundrak lkundrak force-pushed the th/no-gasyncresult branch 2 times, most recently from f1ca166 to ff33c79 Compare October 12, 2018 14:44
@thom311 thom311 mentioned this pull request Oct 13, 2018
…Result pattern

All operations must be cancellable in a timely manner, otherwise, the objects
hang during shutdown.

Also, get rid of the GAsyncResult pattern. It is more cumbersome than
helpful.

There are still several issues, marked by FIXME comments.
We should not use GAsyncResult. At least, not for internal API.

It's more cumbersome then helpful, in my opinion. It requires
this awkward async_finish() pattern.

Instead, let the caller pass a suitable callback of the right type.
Previously nm_ppp_manager_stop() would return a handle which
makes it easy to cancel the operation.

However, sometimes, we may want to cancel an operation based on
an GCancellable. So, extend nm_ppp_manager_stop() to hook it
with a cancellable.

Essentially, move the code from nm-modem.c to nm-ppp-manager-call.c,
where it belongs and where the functionality gets available to every
component.
- fix stopping ppp-manager. Previously, we would take a reference
  to priv->ppp_manager to cancel it later. However, deactivate_cleanup()
  is called first, which already issues nm_ppp_manager_stop().
  Thereby, not using a callback and not waiting for the operation
  to complete.

- get rid of this "step" state machine. There are litterally two steps
  that need to be performed asynchornously. Instead chain the calls.

- it is now obviously visible, that the async callback never completes
  synchronously upon being called (provided that all async operations
  that it calls themself have this behavior -- which they should).
@bengal
Copy link
Contributor

bengal commented Oct 16, 2018

LGTM

Copy link
Member

@lkundrak lkundrak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more cumbersome then helpful, in my opinion. It requires this awkward async_finish() pattern.

Well; whether it's awkward ot not is purely a matter of taste.

Good thing that you get rid of a handful of GSimpleAsyncResults though. Those are not portable to more recent GLib versions.

@thom311
Copy link
Member Author

thom311 commented Oct 17, 2018

merged

@thom311 thom311 closed this Oct 17, 2018
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 2, 2021 20:59
@lkundrak lkundrak restored the th/no-gasyncresult branch February 2, 2021 22:05
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 3, 2021 06:10
@lkundrak lkundrak restored the th/no-gasyncresult branch February 3, 2021 06:13
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 4, 2021 05:54
@lkundrak lkundrak restored the th/no-gasyncresult branch February 4, 2021 06:01
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 4, 2021 08:46
@lkundrak lkundrak restored the th/no-gasyncresult branch February 4, 2021 08:53
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 7, 2021 11:30
@lkundrak lkundrak restored the th/no-gasyncresult branch February 7, 2021 11:33
@lkundrak lkundrak deleted the th/no-gasyncresult branch February 8, 2021 21:31
@lkundrak lkundrak restored the th/no-gasyncresult branch February 8, 2021 21:33
@lkundrak lkundrak deleted the th/no-gasyncresult branch August 13, 2021 07:00
@lkundrak lkundrak restored the th/no-gasyncresult branch August 13, 2021 07:02
@lkundrak lkundrak deleted the th/no-gasyncresult branch August 27, 2021 04:48
@lkundrak lkundrak restored the th/no-gasyncresult branch August 27, 2021 05:22
@lkundrak lkundrak deleted the th/no-gasyncresult branch January 28, 2022 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants