Skip to content

Commit

Permalink
Add DispatchSync extension
Browse files Browse the repository at this point in the history
  • Loading branch information
borland committed Aug 24, 2015
1 parent a89e4d9 commit bf95605
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions SerialQueue/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@ public interface IThreadPool
IDisposable Schedule(TimeSpan dueTime, Action action);
}

/// <summary>Useful extension methods for queues</summary>
public static class IDispatchQueueExtensions
{
/// <summary>A wrapper over DispatchSync that calls a value-producing function and returns it's result</summary>
/// <typeparam name="T">Result type</typeparam>
/// <param name="queue">The queue to execute the function on</param>
/// <param name="func">The function to execute</param>
/// <returns>The return value of func</returns>
public static T DispatchSync<T>(this IDispatchQueue queue, Func<T> func)
{
T result = default(T);
queue.DispatchSync(() => { result = func(); });
return result;
}
}
}

0 comments on commit bf95605

Please sign in to comment.