package main

import (
	"fmt"
	"time"
)

// section: main
func main() {
	now := time.Now()

	// use an anonymous function to scope variables to be used in the defer
	defer func(now time.Time) {
		fmt.Printf("time since program started: %s\n", time.Since(now))
	}(now)

	fmt.Println("sleeping for 2 seconds...")
	time.Sleep(2 * time.Second)
}

// section: main

/*
// section: output
sleeping for 2 seconds...
time since program started: 2.004430822s
// section: output
*/
