Added UpdateWhile

This commit is contained in:
Garry Newman 2016-11-03 10:57:52 +00:00
parent 65dec9d809
commit 947fc190d2
3 changed files with 23 additions and 5 deletions

View File

@ -29,11 +29,8 @@ public void StatsGet()
Assert.IsTrue( deathsInCallback > 0 );
} );
while ( !GotStats )
{
server.Update();
Thread.Sleep( 10 );
}
server.UpdateWhile( () => !GotStats );
var deaths = server.Stats.GetInt( MySteamId, "deaths", -1 );
Console.WriteLine( "deathsInCallback: {0}", deaths );

View File

@ -14,6 +14,13 @@
Called with a message from Steam
</summary>
</member>
<member name="M:Facepunch.Steamworks.BaseSteamworks.UpdateWhile(System.Func{System.Boolean})">
<summary>
Run Update until func returns false.
This will cause your program to lock up until it finishes.
This is useful for things like tests or command line utilities etc.
</summary>
</member>
<member name="T:Facepunch.Steamworks.Inventory.Item">
<summary>
An item in your inventory.

View File

@ -94,5 +94,19 @@ public virtual void Update()
if ( OnUpdate != null )
OnUpdate();
}
/// <summary>
/// Run Update until func returns false.
/// This will cause your program to lock up until it finishes.
/// This is useful for things like tests or command line utilities etc.
/// </summary>
public void UpdateWhile( Func<bool> func )
{
while ( func() )
{
Update();
System.Threading.Thread.Sleep( 1 );
}
}
}
}