Fiber
Fibers Lighweight Cooperative Multitasking
DelayedCache.cs
1 // Copyright 2019 (C) paul@marrington.net http://www.askowl.net/unity-packages
2 
3 using System;
4 using Askowl;
5 /// <a href="http://bit.ly/2BkDrzH">Disposed does not recycle object immediately</a>
6 public class DelayedCache<T> : IDisposable where T : DelayedCache<T> {
7  /// <a href="http://bit.ly/2BkDrzH">It behaves like Askowl.Cached from Able</a>
8  public static T Instance => Cache<T>.Instance;
9 
10  /// <a href="http://bit.ly/2BkDrzH">How many Unity frames do we delay for (default 10)</a>
11  public int Frames = 10;
12 
13  protected DelayedCache() => disposalFiber = Fiber.Instance.SkipFrames(Frames).Do(_ => Cache<T>.Dispose(this as T));
14 
15  private readonly Fiber disposalFiber;
16 
17  public void Dispose() => disposalFiber.Go();
18 }
Definition: Emitter.cs:6
Fiber Do(Action nextAction, string name=null)
Business logic activation step
lightweight cooperative multi-tasking
Definition: Fiber.cs:10
Fiber Go()
Start a fiber if it is not already running
static T Instance
It behaves like Askowl.Cached from Able
Definition: DelayedCache.cs:8
int Frames
How many Unity frames do we delay for (default 10)
Definition: DelayedCache.cs:11
static Fiber Instance
Precompile an instance of a fiber command
Definition: Fiber.cs:22
Disposed does not recycle object immediately
Definition: DelayedCache.cs:6
Fiber SkipFrames(int framesToSkip)
Wait a specific count of Update, FixedUpdate or LateUpdate frames