Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task<LifeTime> Life(Person me)
- {
- while (me.alive)
- {
- try
- {
- //
- //...
- //
- }
- catch (Exception x)
- {
- bool result= await me.DoSomeWork(()=>Shop.Buy(Goods.Vodka, me)); //await in catch - c# 6
- if (result)
- {
- me.Use(await me.GetItem(Goods.Vodka));
- //
- //...
- //
- }
- else
- {
- Debug.WriteLine("life sucks");
- }
- }
- }
- return new LifeTime(me);
- }
- }
- public class LifeTime
- {
- public LifeTime(Person me)
- {
- //
- //...
- //
- }
- }
- public class Person
- {
- public void Use(Item i)
- {
- //
- //...
- //
- }
- public async Task<bool> DoSomeWork(Func<Task<bool>> work)
- {
- return await AsyncInfo.Run(c => work());
- }
- public async Task<Item> GetItem(Goods item)
- {
- return Things[item];
- }
- public bool alive { get; private set; }
- public Dictionary<Goods, Item> Things = new Dictionary<Goods, Item>();
- }
- public static class Shop
- {
- public static async Task<bool> Buy(Goods vodka, Person me)
- {
- //
- //...
- //
- return true;
- }
- }
- public enum Goods
- {
- Vodka
- }
- public class Item
- {
- }
- public class Vodka : Item
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement