I’m wondering what is the idiomatic way to create this function in go
protected static T WaitForValue<T>(Func<T> act, T expectedVal, int timeout = 15000, int interval = 16)
{
if (Debugger.IsAttached)
timeout *= 100;
var sw = Stopwatch.StartNew();
do
{
try
{
var currentVal = act();
if (expectedVal.Equals(currentVal))
{
return currentVal;
}
if (sw.ElapsedMilliseconds > timeout)
{
return currentVal;
}
}
catch
{
if (sw.ElapsedMilliseconds > timeout)
{
throw;
}
}
Thread.Sleep(interval);
} while (true);
}