Code Explainers

Code explainers tagged #timers

typescript
import { Pipe, PipeTransform, ChangeDetectorRef, NgZone, OnDestroy } from '@angular/core';
 
@Pipe({
  name: 'timeAgo',

A self-refreshing timeAgo pipe in Angular

impure-pipe change-detection timers
Advanced 10 steps
go
package debounce
 
import (
	"sync"

Building a debouncer in Go

concurrency debounce timers
Intermediate 6 steps
javascript
function debounce(fn, delay) {
  let timeoutId = null;
 
  function debounced(...args) {

Building a debounce function in JavaScript

closures timers higher-order-functions
Intermediate 6 steps
javascript
function throttle(fn, wait) {
  let lastCall = 0;
  let timeoutId = null;
  let lastArgs = null;

Building a leading-and-trailing throttle

closures rate-limiting timers
Advanced 6 steps