public void cancelTimer(IPollEvents sink, int id)
    {
        assert (Thread.currentThread() == worker);

        TimerInfo copy = new TimerInfo(sink, id);
        //  Complexity of this operation is O(n). We assume it is rarely used.

        TimerInfo timerInfo = timers.find(copy);
        if (timerInfo != null) {
            // let's defer the removal during the loop
            timerInfo.cancelled = true;
        }
    }
@Test
    public void testCancelTimer()
    {
        final PollerBaseTested poller = new PollerBaseTested();

        poller.addTimer(1000, sink, 1);
        long timeout = poller.executeTimers();

        assertThat(timeout, is(1000L));
        assertThat(poller.isEmpty(), is(false));

        poller.cancelTimer(sink, 1);
        timeout = poller.executeTimers();

        assertThat(timeout, is(0L));
        assertThat(poller.isEmpty(), is(true));
    }