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.

Replace IGuardClose.CanClose with CanCloseAsync

See original GitHub issue

The current syntax of CanClose with a callback is quite difficult to chain. For example, if I’m deriving from a class already overriding CanClose and want to first check that it allowed closing before adding my own condition, the code will look like this:

public override void CanClose(Action<bool> callback) {
  base.CanClose(result => callback(result && condition));
}

By making CanCloseAsync, it’s way more natural IMO:

public override Task<bool> CanCloseAsync() {
  return await base.CanCloseAsync() && condition();
}

Plus, it allows to call other asynchronous methods easily. Of course, that would be a breaking change, unless a new interface is implemented.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
enrico-padovanicommented, Apr 13, 2018

Hi folks!

Any progress on this / ETA for v4? In my specific case I’m using MahApps message which is implemented in async way. So when trying to close a screen, I’d like to ask for modification discard. Perhaps someone has solved this problem.

1reaction
nigel-sampsoncommented, Aug 20, 2014

Would be good to have a second interface for this, otherwise we’re back to breaking changes and needing to release 3.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Replace IGuardClose.CanClose with CanCloseAsync
Replace IGuardClose.CanClose with CanCloseAsync. ... The current syntax of CanClose with a callback is quite difficult to chain.
Read more >
Caliburn.Micro v4.0.136-rc release notes (2020-06-21) | LibHunt
Close is being called before Closing has finished, when CanCloseAsync executes too quickly. 9f82a08 Merge pull request #1 from Caliburn-Micro/master ...
Read more >
Untitled
... proxy server nederland Methods on a Form Microsoft Learn Replace IGuardClose.CanClose with CanCloseAsync #86 - Github WebMar 16, 2023 · canClose: ...
Read more >
NavigatingCancelEventArgs, Windows.UI.Xaml.Navigation ...
CanCloseAsync (); if (!task. ... DataContext as IGuardClose; if (guard != null) { var shouldCancel = false; guard.CanClose(result => { shouldCancel = !result ......
Read more >
Screens and Conductors - canton7/Stylet GitHub Wiki
IGuardClose : Used to ask the ViewModel whether it can close. Has a CanCloseAsync method. IViewAware : Sometimes a ViewModel needs to know ......
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