code: func (c *AMRMClientAsync) periodicAllocate() {
  	for {
  		select {
  		case <-c.stop:
  			log.Println("stop notification received. stopping allocate routine.")
  			return
  		default:
  		}
  
  		response, err := c.client.Allocate()
  
  		if err != nil {
  			log.Println("async allocate failed. terminating periodic allocate. error: ", err)
  			return
  		}
  
  		if command := response.GetAMCommand(); command != 0 {
  			switch command {
  			case hadoop_yarn.AMCommandProto_AM_RESYNC, hadoop_yarn.AMCommandProto_AM_SHUTDOWN:
  				log.Println("received command: %s. invoking shutdown and stopping allocate routine.", command)
  				c.handler.OnShutDownRequest()
  				return
  			default:
  				log.Printf("unknown command: %s. stopping allocate routine.", command)
  				return
  			}
  		}
  
  		if completedContainers := response.CompletedContainerStatuses; completedContainers != nil {
  			if len(completedContainers) > 0 {
  				c.handler.OnContainersCompleted(completedContainers)
  			}
  		}
  
  		if allocatedContainers := response.AllocatedContainers; allocatedContainers != nil {
  			if len(allocatedContainers) > 0 {
  				c.handler.OnContainersAllocated(allocatedContainers)
  			}
  		}
  
  		if updatedNodes := response.UpdatedNodes; updatedNodes != nil {
  			if len(updatedNodes) > 0 {
  				c.handler.OnNodesUpdated(updatedNodes)
  			}
  		}
  
  		time.Sleep(time.Duration(c.intervalMs) * time.Millisecond)
  	}
  }
docs: //Periodically call the  the Resource Manager with an allocate call