code: func awaitScanComplete(p *rc.Process) time.Duration {
  	log.Println("Awaiting scan completion...")
  	var t0, t1 time.Time
  	lastEvent := 0
  loop:
  	for {
  		evs, err := p.Events(lastEvent)
  		if err != nil {
  			continue
  		}
  
  		for _, ev := range evs {
  			if ev.Type == "StateChanged" {
  				data := ev.Data.(map[string]interface{})
  				log.Println(ev)
  
  				if data["to"].(string) == "scanning" {
  					t0 = ev.Time
  					continue
  				}
  
  				if !t0.IsZero() && data["to"].(string) == "idle" {
  					t1 = ev.Time
  					break loop
  				}
  			}
  			lastEvent = ev.ID
  		}
  
  		time.Sleep(250 * time.Millisecond)
  	}
  
  	return t1.Sub(t0)
  }
docs: // awaitScanComplete waits for a folder to transition idle->scanning and
  // then scanning->idle and returns the time taken for the scan.