The following example seems to work, but is it safe to use? My goal is to do some very light background processing (whereas an actual task queue job feels too heavy).
func MyHandler(w http.ResponseWriter, r *http.Request) {
go func() {
// do something ...
}()
return // 200
}
Goroutines that outlive the request are not supported, but you can use runtime.RunInBackground to execute code in a background goroutine:
The provided function will be invoked with a background context that is distinct from (and may outlast) the provided context. Note that there is a limit of 10 simultaneous background requests per instance. Here is another example.
Please note that Goroutines that live within the context of a request, are supported though:
Just remember, folks, there is a world of difference between concurrency and parallel operation. This stumped me for a while (still does sometimes). See what Rob Pike says: https://www.youtube.com/watch?v=oV9rvDllKEg
In other words, yes, AppEngine can handle goroutines -- this is not being parallel. This is running the code the most efficient way possible and is a precursor to being able to run the code in parallel...