A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
970B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Svelto.Tasks;
  7. using Svelto.Tasks.Enumerators;
  8. namespace GamecraftModdingAPI.Tasks
  9. {
  10. /// <summary>
  11. /// An asynchronous task to be performed once
  12. /// </summary>
  13. public class Once : ISchedulable
  14. {
  15. private Action task;
  16. private float delay;
  17. public IEnumerator<TaskContract> Run()
  18. {
  19. yield return new WaitForSecondsEnumerator(delay).Continue();
  20. task();
  21. yield return Yield.It;
  22. }
  23. /// <summary>
  24. /// Construct a single-run task
  25. /// </summary>
  26. /// <param name="task">The task to run once</param>
  27. /// <param name="after">The delay (in seconds) before the task is run</param>
  28. public Once(Action task, float after = 0.0f)
  29. {
  30. this.task = task;
  31. this.delay = after;
  32. }
  33. }
  34. }