RxJS simulates App to exit the function. If you click twice in two seconds, you will exit.

problem description

use RxJS to simulate the two-click exit function of App.
uses two methods, both of which are not very satisfactory. Is there a better way?

related codes

method 1: the problem with using the bufferTime operator
is that the buffer time of bufferTime does not start with a click, which may cause a value to be issued immediately after a click

click$.pipe(
  throttleTime(2000),
  tap(() => console.log("one")),
  concatMap(() => click$.pipe(
    tap(() => console.log("two")),
    take(1),
    takeUntil(of(1).pipe(delay(2000)))
  ))
).subscribe(v => console.log("success"))
< hr >

finally see my supplement downstairs

Jul.14,2021

click$
  .map(t => Date.now())
  .scan((prev, cur) => ({
    cur,
    result: cur - prev.cur
  }), {
    cur: 0
  })
  .map(t => t.result / 1000)
  .filter(t => t < 2)
  .take(1)
  .subscribe(t => {
    console.log(t)
  });
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be7a88-3189a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be7a88-3189a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?