You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-14 22:30:10 +00:00
com.unity.ide.visualstudio@2.0.9
## [2.0.9] - 2021-05-04 Project generation: Added support for CLI. Integration: Improved performance when discovering Visual Studio installations. Warn when legacy assemblies are present in the project. Warn when the package version is not up-to-date.
This commit is contained in:
76
Editor/AsyncOperation.cs
Normal file
76
Editor/AsyncOperation.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Unity Technologies.
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
internal class AsyncOperation<T>
|
||||
{
|
||||
private readonly Func<T> _producer;
|
||||
private readonly ManualResetEventSlim _resetEvent;
|
||||
|
||||
private T _result;
|
||||
private Exception _exception;
|
||||
|
||||
private AsyncOperation(Func<T> producer)
|
||||
{
|
||||
_producer = producer;
|
||||
_resetEvent = new ManualResetEventSlim(initialState: false);
|
||||
}
|
||||
|
||||
public static AsyncOperation<T> Run(Func<T> producer)
|
||||
{
|
||||
var task = new AsyncOperation<T>(producer);
|
||||
task.Run();
|
||||
return task;
|
||||
}
|
||||
|
||||
private void Run()
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(_ =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_result = _producer();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_exception = e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_resetEvent.Set();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void CheckCompletion()
|
||||
{
|
||||
if (!_resetEvent.IsSet)
|
||||
_resetEvent.Wait();
|
||||
}
|
||||
|
||||
|
||||
public T Result
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckCompletion();
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
|
||||
public Exception Exception
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckCompletion();
|
||||
return _exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user