pmndrs / directed

A flexible, minimal scheduler written in TypeScript
MIT License
25 stars 1 forks source link

Schedule runnables to run once #10

Open krispya opened 3 months ago

krispya commented 3 months ago

An example is an init function. A work around is to early out after the first run, but it would be even better if it were just removed from the sort entirely.

I figure the API can look like this, though I don't know the best way it could be implemented.

test('scheduling runnables once', () => {
    const schedule = create();

    add(schedule, aFn, id('A'), once());
    add(schedule, bFn, after('A'), id('B'));
    add(schedule, cFn, after('B'), id('C'));

    run(schedule, {});

    expect(order).toEqual(['A', 'B', 'C']);

    order = [];
    run(schedule, {});

    expect(order).toEqual(['B', 'C']);
})
akdjr commented 2 months ago

Depends on #15 and a bit of #17 in order to not wreck references and allow maximum flexibility with the once modifier.