[Go] Studying an approach for integration with context.Context
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 1.6k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 126
Description
Hi there,
I am new to FoundationDB and was looking around in the issue tracker for closed issues/PRs about this topic but could not find any.
I have been reading also this interesting conversation from 2014: https://groups.google.com/g/golang-nuts/c/SPjQEcsdORA
My question is: how would one integrate Go's `context.Context` when using the Go binding of FoundationDB? I can imagine that the idea has already been explored; ideally I could contribute with some documentation/example/PR afterwards.
I mostly wonder if it would require a re-hash of this old approach for the waiting mechanisms (most likely not): https://gist.github.com/ipeters/4bc867c5e093679ab145
and what guarantees can be kept once `context.Context` is handled.
An example of the use case I am referring to:
```go
package main
import (
"fmt"
"log"
"net/http"
"github.com/apple/foundationdb/bindings/go/src/fdb"
)
var db fdb.Database
func hello(w http.ResponseWriter, req *http.Request) {
// USE-CASE: let's cancel 'db.Transact' when req.Context() is cancelled
ret, e := db.Transact(func(tr fdb.Transaction) (interface{}, error) {
tr.Set(fdb.Key("hello"), []byte("world"))
return tr.Get(fdb.Key("foo")).MustGet(), nil
})
if e != nil {
log.Fatalf("Unable to perform FDB transaction (%v)", e)
}
fmt.Fprintf(w, "hello is now world, foo was: %s\n", string(ret.([]byte)))
}
func main() {
fdb.MustAPIVersion(720)
db = fdb.MustOpenDefault()
http.HandleFunc("/hello", hello)
http.ListenAndServe(":8090", nil)
}
```
Contributor guide
Research direction
Start with the Go binding entry point db.Transact and the request entry point req.Context() shown in the example, then review the linked golang-nuts conversation and waiting-mechanism gist. Done would be a decided, documented approach or scoped implementation plan describing cancellation behavior and its guarantees.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100