Skip to content

Commit

Permalink
use completion source
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitii committed Apr 17, 2022
1 parent e4feb2c commit e205c9c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Community.Wsl.Sdk/Strategies/Commands/StreamDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public void Fetch()
var data = stream.ToArray();
Finished(data);
}
) { IsBackground = true };
)
{
IsBackground = true
};

_thread.Start();
}
Expand All @@ -57,7 +60,7 @@ public virtual void CopyResultTo(ref CommandResult result, bool isStdOut)
throw new Exception("Data hasn't been fetched, yet!");
}

if (_thread.ThreadState != ThreadState.Stopped)
if (!_completionSource?.Task.IsCompleted ?? false)
{
throw new Exception("Fetching hasn't been finished, yet!");
}
Expand All @@ -84,6 +87,6 @@ public Task WaitAsync()
return Task.CompletedTask;
}

return _completionSource.Task.ContinueWith(task => Task.Delay(1), TaskScheduler.Default);
return _completionSource.Task;
}
}

0 comments on commit e205c9c

Please sign in to comment.