namespace Engine.Resource;

public class ResourceHandle<T>
{
  public T? Value
  {
    get
    {
      if (_isLoaded)
      {
        return _value!;
      }

      if (!_task.IsCompleted)
      {
        return _defaultValue;
      }

      _value = _task.Result;
      _isLoaded = true;

      return _value!;
    }
  }

  private readonly T? _defaultValue;
  private readonly Task<T> _task;
  private T? _value;
  private bool _isLoaded;

  public ResourceHandle(Task<T> parTask, T? parDefaultValue)
  {
    _defaultValue = parDefaultValue;
    _task = parTask;
  }
}