Skip to content

v5: RunAsync and more

Compare
Choose a tag to compare
@justdmitry justdmitry released this 14 Feb 11:19
· 38 commits to master since this release
v5.0.0
  1. IRunnable changes
    1. void Run(...) changed to Task RunAsync(...) (from #1)
      Now it's easier to write async code (but inside it's still one Task from thread pool that wait your code for complete and sleep between runs, no magic here).
    2. IServiceProvider added as RunAsync parameter
      You should use it for obtaining scoped-lifetime objects in case you force you IRunnable be singleton (in AddTask, see below).
  2. Startup.cs changes
    1. You may change lifetime of your IRunnable when calling AddTask<>. It's Transient by default, but you may change it: services.AddTask<MyFirstTask>(ServiceLifetime.Singleton)
      Important! No matter what lifetime your IRunnable has - every RunAsync is called inside new/own scope (disposed after run). Use IServiceProvider passed as parameter for correct service resolution!
    2. You may pass CancellationToken to StartTask, and task will be stopped when this token got cancelled (issue #3)
  3. ITask changes
    1. Events BeforeRun, AfterRunSuccess and AfterRunFail replaced with async Func's - that's easier than async EventHandlers and EventArgs.