0

I'm new to Go and I want to call a function repeatedly and asynchronously after a specific time interval just like how the setInterval() function works in JavaScript. I want to build an API which returns some news headlines from different websites but scraping the websites on every request would be very slow. So, I want to call the web scraping function asynchronously in the background after every 10 minutes to update the headline data.

// I want to call this function every 10 minutes
func WebScraper(data map[string]interface{}) {  
    // Web scraping stuff
}

How can I do this?

Titan
  • 45
  • 1
  • 7
  • is there a easier way to do this? Like a single function which would take the web scraping function as argument and the time interval as argument and run it in the background? – Titan Aug 20 '22 at 07:22
  • 3
    `go func() { for range time.NewTicker(time.Minute * 10).C { doSomeThing() }}()` – Charlie Tumahai Aug 20 '22 at 07:30

0 Answers0