Skip to content

Commit

Permalink
Merge pull request #6023 from peppy/inline-delegate-add-once
Browse files Browse the repository at this point in the history
Add notes regarding using inline delegates with `Scheduler.AddOnce`
  • Loading branch information
bdach authored Oct 10, 2023
2 parents 238fa68 + 5fd6cf5 commit ba72c19
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions osu.Framework.Tests/Threading/SchedulerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ public void TestAddOnceInlineDelegate()
{
classInvocations = 0;

// Note that while this works here (even with a capture), there's no guarantee that will always be the
// case. As such it's always best to use a local function or private method.
for (int i = 0; i < 10; i++)
invokeInlineDelegateAction();

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Threading/Scheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public bool AddOnce<T>(Action<T> task, T data)
/// Adds a task which will only be run once per frame, no matter how many times it was scheduled in the previous frame.
/// </summary>
/// <remarks>The task will be run on the next <see cref="Update"/> independent of the current clock time.</remarks>
/// <param name="task">The work to be done.</param>
/// <param name="task">The work to be done. Avoid using inline delegates as they may not be cached, bypassing the once-per-frame guarantee.</param>
/// <returns>Whether this is the first queue attempt of this work.</returns>
public bool AddOnce(Action task)
{
Expand Down

0 comments on commit ba72c19

Please sign in to comment.