Internal interfaces do the await callback automatically

This commit is contained in:
Garry Newman 2019-04-13 21:20:07 +01:00
parent cce25e6f77
commit d9da40c0e8
5 changed files with 22 additions and 9 deletions

View File

@ -16,13 +16,23 @@ public SteamApiCallback( ulong callbackHandle )
CallHandle = callbackHandle;
}
public bool IsComplete()
public bool IsComplete( out bool failed )
{
return Utils.IsCallComplete( CallHandle, out bool failed );
return Utils.IsCallComplete( CallHandle, out failed );
}
public T? GetResult()
public async Task<T?> GetResult()
{
bool failed = false;
while ( !IsComplete( out failed ) )
{
await Task.Delay( 1 );
}
if ( failed )
return null;
return Utils.GetResult<T>( CallHandle );
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using SteamNative;
@ -337,9 +338,9 @@ public void RequestAllProofOfPurchaseKeys()
private GetFileDetailsDelegate GetFileDetailsDelegatePointer;
#endregion
public SteamApiCallback<FileDetailsResult_t> GetFileDetails( string pszFileName )
public async Task<FileDetailsResult_t?> GetFileDetails( string pszFileName )
{
return new SteamApiCallback<FileDetailsResult_t>( GetFileDetailsDelegatePointer( Self, pszFileName ) );
return await (new SteamApiCallback<FileDetailsResult_t>( GetFileDetailsDelegatePointer( Self, pszFileName ) )).GetResult();
}
#region FunctionMeta

View File

@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using SteamNative;
@ -266,9 +267,9 @@ public bool BOverlayNeedsPresent()
private CheckFileSignatureDelegate CheckFileSignatureDelegatePointer;
#endregion
public SteamApiCallback<CheckFileSignature_t> CheckFileSignature( string szFileName )
public async Task<CheckFileSignature_t?> CheckFileSignature( string szFileName )
{
return new SteamApiCallback<CheckFileSignature_t>( CheckFileSignatureDelegatePointer( Self, szFileName ) );
return await (new SteamApiCallback<CheckFileSignature_t>( CheckFileSignatureDelegatePointer( Self, szFileName ) )).GetResult();
}
#region FunctionMeta

View File

@ -17,6 +17,7 @@ public void GenerateVTableClass( string className, string filename )
WriteLine( $"using System;" );
WriteLine( $"using System.Runtime.InteropServices;" );
WriteLine( $"using System.Text;" );
WriteLine( $"using System.Threading.Tasks;" );
WriteLine( $"using SteamNative;" );
WriteLine();

View File

@ -73,8 +73,8 @@ internal class SteamApiCallType : BaseType
{
public string CallResult;
public override string TypeName => "SteamAPICall_t";
public override string Return( string varname ) => $"return new SteamApiCallback<{CallResult}>( {varname} );";
public override string ReturnType => $"SteamApiCallback<{CallResult}>";
public override string Return( string varname ) => $"return await (new SteamApiCallback<{CallResult}>( {varname} )).GetResult();";
public override string ReturnType => $"async Task<{CallResult}?>";
}
internal class CSteamIdType : BaseType