//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
namespace BansheeEngine
{
/** @addtogroup Utility
* @{
*/
///
/// Object you may use to check on the results of an asynchronous operation. Contains uninitialized data until
/// returns true.
///
public class AsyncOp : ScriptObject
{
///
/// Constructs a new async operation.
///
internal AsyncOp() // Note: For internal runtime use only
{
Internal_CreateInstance(this);
}
///
/// Checks has the asynchronous operation completed.
///
public bool IsCompleted
{
get
{
bool value;
Internal_IsComplete(mCachedPtr, out value);
return value;
}
}
///
/// Retrieves the value returned by the async operation. Only valid if returns true.
///
/// Type of the return value. Caller must ensure to provide the valid type.
/// Return value of the async operation.
public T GetReturnValue()
{
return (T)Internal_GetReturnValue(mCachedPtr);
}
///
/// Blocks the calling thread until asynchronous operation completes.
///
public void BlockUntilComplete()
{
Internal_BlockUntilComplete(mCachedPtr);
}
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Internal_CreateInstance(AsyncOp managedInstance);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Internal_IsComplete(IntPtr thisPtr, out bool value);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern object Internal_GetReturnValue(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern void Internal_BlockUntilComplete(IntPtr thisPtr);
}
/** @} */
}