12.0.5 • Published 2 years ago

happenstance v12.0.5

Weekly downloads
60
License
MIT
Repository
github
Last release
2 years ago

Build Status Coverage Status Stories in Ready

TK: All out dated! Ugh!

Happenstance is a scheduler. You put values in it. They come back out when the time is right. It doesn't set timers, so you'll need to check with it at regular intervals.

var Scheduler = require('happenstance')

var scheduler = new Scheduler

scheduler.schedule('a', 1, Date.now() + 30000)
scheduler.schedule('b', 1, Date.now() + 30000)
scheduler.schedule('c', 3, Date.now() + 120000)

scheduler.unschedule('b')

setTimeout(function () {
    console.log('after one minute')
    console.log(scheduler.check(Date.now()).pop())
    setTimeout(function () {
        console.log('after two and a half minutes')
        console.log(scheduler.check(Date.now()).pop())
    }, 90000)
}, 60000)

The above program will print the following.

$ node schedule.js
after one minute
1
after two and a half minutes
3

new Scheduler

Createa new Scheduler object.

scheduler.schedule(key, value, when)

Options are:

  • key an key that you can use to remove the event using unschedule.
  • value the value returned when the event is due.
  • when time time after which the event is due.

scheduler.unschedule(key)

Unschedule the event with the given key.

scheduler.check(now)

Return any events currently due.

scheduler.clear()

Clear all scheduled events.

Diary

This is all seeming very dubious now. It seems like it would be better to have a clock rather than a range for a delay.

console.log(scheduler.tick())
scheduler.schedule(key, value, 1, 4)
scheduler.check().forEach(doWork)

The above would pull a random number from the random number generator that would be used for all delays in the next series of ticks.

The only immediate downstream is Paxos, and it doesn't really need to stagger its events, since events going to eminate out from the core of the algorithm, there is no point in providing back-off logic.

Okay, so it is not here, I've removed delay ranges, because that's back-off stuff and it doesn't belong here, it should be just external so you can record it for replaying.

13.0.0-alpha.1

2 years ago

13.0.0-alpha.0

3 years ago

12.0.5

3 years ago

12.0.4

3 years ago

12.0.3

4 years ago

12.0.2

5 years ago

12.0.1

5 years ago

12.0.0

5 years ago

11.0.3

5 years ago

11.0.2

5 years ago

11.0.1

5 years ago

11.0.0

5 years ago

10.17.0

5 years ago

10.16.0

5 years ago

10.15.0

5 years ago

10.14.0

5 years ago

10.13.0

5 years ago

10.12.0

5 years ago

10.11.0

5 years ago

10.10.0

5 years ago

10.9.0

6 years ago

10.8.0

6 years ago

10.7.0

6 years ago

10.6.0

6 years ago

10.5.0

6 years ago

10.4.1

6 years ago

10.4.0

6 years ago

10.3.2

6 years ago

10.3.1

6 years ago

10.3.0

6 years ago

10.2.0

6 years ago

10.1.0

6 years ago

10.0.1

6 years ago

10.0.0

6 years ago

9.0.2

6 years ago

9.0.1

6 years ago

9.0.0

6 years ago

8.0.0

6 years ago

7.0.0

6 years ago

6.0.0

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.0.0

7 years ago

3.6.0

7 years ago

3.5.0

7 years ago

3.4.1

7 years ago

3.4.0

7 years ago

3.3.0

7 years ago

3.2.0

7 years ago

3.1.0

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.8.4

7 years ago

2.8.3

7 years ago

2.8.2

7 years ago

2.8.1

7 years ago

2.8.0

7 years ago

2.7.1

7 years ago

2.7.0

8 years ago

2.6.0

8 years ago

2.5.0

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.14

8 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.6

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago