Giter Club home page Giter Club logo

Comments (11)

jamesmh avatar jamesmh commented on July 30, 2024 1

@papakaliati - create a new branch off the current master branch (a nice new clean one). You'll see that the scheduler is quite different now.

So, basically, add a new method to IScheduledEventConfiguration :

IScheduledEventConfiguration When(Func<Task> predicate);

Internally, the ScheduledEvent will implement this new method.

Just add one private field to hold Func<Task> (so only one predicate is ever used).

Put the check in InvokeScheduledEvent as the first thing. If When is not null, and it returns false, then return right away. Otherwise, keep going as normal.

Hopefully that make sense?

Thanks for the help!

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

Reporting for duty.

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

Hmm can't see you in the list. O well. I'll let you know when things are ready to go 👍

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

lol Ya, actually I meant Func<Task<bool>>.

So that call should be awaited when being checked in the ScheduledEvent .

Sorry about that!

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

I think just using Func<Task<bool>> is fine.

If there's a time when the user doesn't need to use an async method / await, they should be able to use return Task.FromResult(true);

So some good unit tests you could build are something like:

bool shouldRun = true;

scheduler
    .Schedule(someAction)
    .When(() => return Task.FromResult(shouldRun)); 

And maybe another one something like this:

Func<Task<bool>> shouldRun = () => Task.FromResult(true);

scheduler
    .Schedule(someAction)
    .When(shouldRun); 

And to include awaiting:

Func<Task<bool>> shouldRun = async () =>
{
     await Task.Delay(0);
     return true;
}

scheduler
    .Schedule(someAction)
    .When(shouldRun); 

And of course, some cases when "shouldRun" is false and make sure the task didn't run. Those are just off the top of my head... hopefully they ok lol.

Thanks @papakaliati !

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

from coravel.

jamesmh avatar jamesmh commented on July 30, 2024

Done at #32

from coravel.

papakaliati avatar papakaliati commented on July 30, 2024

Cheers mate, thanks 👍

from coravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.