Implement Queue#pop(timeout: sec)

[Feature #18774]

As well as `SizedQueue#pop(timeout: sec)`

If both `non_block=true` and `timeout:` are supplied, ArgumentError
is raised.
This commit is contained in:
Jean Boussier 2022-07-26 17:40:00 +02:00
parent ec3f59309e
commit e3aabe93aa
Notes: git 2022-08-02 18:04:59 +09:00
10 changed files with 238 additions and 75 deletions

View file

@ -36,6 +36,7 @@
#define RB_HRTIME_PER_MSEC (RB_HRTIME_PER_USEC * (rb_hrtime_t)1000)
#define RB_HRTIME_PER_SEC (RB_HRTIME_PER_MSEC * (rb_hrtime_t)1000)
#define RB_HRTIME_MAX UINT64_MAX
#define RB_HRTIME_MIN ((rb_hrtime_t)0)
/*
* Lets try to support time travelers. Lets assume anybody with a time machine
@ -91,6 +92,15 @@ rb_hrtime_add(rb_hrtime_t a, rb_hrtime_t b)
return c;
}
static inline rb_hrtime_t
rb_hrtime_sub(rb_hrtime_t a, rb_hrtime_t b)
{
if (a < b) {
return RB_HRTIME_MIN;
}
return a - b;
}
/*
* convert a timeval struct to rb_hrtime_t, clamping at RB_HRTIME_MAX
*/