code: func WithDeadline(parent context.Context, deadline time.Time) (context.Context, context.CancelFunc) {
  	if cur, ok := parent.Deadline(); ok && cur.Before(deadline) {
  		// The current deadline is already sooner than the new one.
  		return context.WithCancel(parent)
  	}
  
  	parent, cancelFunc := context.WithCancel(parent)
  	c := &clockContext{
  		Context:  parent,
  		deadline: deadline,
  	}
  
  	d := deadline.Sub(Now(c))
  	if d <= 0 {
  		// Deadline has already passed.
  		c.setError(context.DeadlineExceeded)
  		cancelFunc()
  		return c, cancelFunc
  	}
  
  	// Invoke our cancelFunc after the specified time. Register the timer now, so
  	// it gets registered in the testclock heap right away (and not at some
  	// undetermined later time when the goroutine starts).
  	t := NewTimer(Tag(c, ContextDeadlineTag))
  	t.Reset(d)
  	go func() {
  		defer t.Stop()
  
  		select {
  		case ar := <-t.GetC():
  			if !ar.Incomplete() {
  				// Timer expired naturally.
  				c.setError(context.DeadlineExceeded)
  				cancelFunc()
  			}
  		case <-c.Done():
  			// Context was canceled, can stop the timer / goroutine.
  			break
  		}
  	}()
  	return c, cancelFunc
  }
docs: // WithDeadline is a clock library implementation of context.WithDeadline that
  // uses the clock library's time features instead of the Go time library.
  //
  // For more information, see context.WithDeadline.