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.

Support async methods on the IActivate interface

See original GitHub issue

A lot of the initial discussion took place in #245, however my thinking has evolved a bit from then.

The initial plan is as follows.

  1. Move the IActivate interface to async only with sync looking like
Task ActivateAsync(CancellationToken cancellationToken);

I’m not 100% on the “Async” suffix, if this was a new codebase that was async first I’d leave it off, however due to migration it make it easier to show where there are breaking changes.

  1. Update the protected methods on Screen that are overridden to the following
Task OnInitializeAsync(CancellationToken cancellationToken);
Task OnActivateAsync(CancellationToken cancellationToken);
  1. Update the ScreenExtensions such as TryActivate in similar ways.
  2. Add some helper extension methods that allow activation without a cancellation token.
  3. Update the Conductor classes in a similar method. This is probably the larger piece of work as it means a lot of methods become async such as ChangeActiveItem and ActivateItem.

Anybody have thoughts on this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
nigel-sampsoncommented, Feb 1, 2018
  1. Not a big fan of adding and then removing it.
  2. Did consider that (although would be = default(CancellationToken) since it’s a value type. But default parameter values can cause some silliness in libraries that overloads don’t have.
  3. Because your view models call into the model layer they need to be async for similar reasons. One of the largest issues is the way the OnInitialize, OnActivate lifecycle happens when the former is async void.

My thought process is to expose the “async” the whole way up the stack, making decisions about “this should be async void to hide stuff” will usually be the wrong decision for someone. Hence ChangeActiveItemAsync etc.

The main point is that the view models won’t do many things async, just better enable you to do them.

There could be some interesting things we can add where if a conductor is switching between items it can cancel the activation of the previous child view model.

1reaction
markgouldcommented, Mar 6, 2018

I’ll start looking at it soon - are you going to push a new alpha to nuget or should we just work off of develop?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making interface implementations async
I'm currently trying to make my application using some Async methods. All my IO is done through explicit implementations of an interface and ......
Read more >
IActivateAudioInterfaceAsyncOpe...
Represents an asynchronous operation activating a WASAPI interface and provides a method to retrieve the results of the activation.
Read more >
ActivateAudioInterfaceAsync function (mmdeviceapi.h)
This function enables Windows Store apps to activate certain WASAPI COM interfaces after using Windows Runtime APIs in the Windows.
Read more >
Is an interface exposing async functions a leaky abstraction?
I would argue the 'asyncness' of a method is indicated by the fact that it returns a Task . The guidelines for suffixing...
Read more >
Designing and Implementing Synchronous vs. ...
If a service method uses the async keyword, it implies that it is an asynchronous method and it might have an await keyword...
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