// GetWithError returns a database value (or nil if there is no value), or an // error if the asynchronous operation associated with this future did not // successfully complete. The current goroutine will be blocked until the future // is ready. func (f FutureValue) GetWithError() ([]byte, error) { if f.set { return f.v, nil } var present C.fdb_bool_t var value *C.uint8_t var length C.int fdb_future_block_until_ready(f.ptr) if err := C.fdb_future_get_value(f.ptr, &present, &value, &length); err != 0 { if err == 2017 { return f.v, nil } else { return nil, Error(err) } } if present != 0 { f.v = C.GoBytes(unsafe.Pointer(value), length) } f.set = true C.fdb_future_release_memory(f.ptr) return f.v, nil }
func (f *futureKey) Get() (Key, error) { f.o.Do(func() { var value *C.uint8_t var length C.int f.BlockUntilReady() if err := C.fdb_future_get_key(f.ptr, &value, &length); err != 0 { f.e = Error{int(err)} } else { f.k = C.GoBytes(unsafe.Pointer(value), length) } C.fdb_future_release_memory(f.ptr) }) return f.k, f.e }
func (f *futureByteSlice) Get() ([]byte, error) { f.o.Do(func() { var present C.fdb_bool_t var value *C.uint8_t var length C.int f.BlockUntilReady() if err := C.fdb_future_get_value(f.ptr, &present, &value, &length); err != 0 { f.e = Error{int(err)} } else { if present != 0 { f.v = C.GoBytes(unsafe.Pointer(value), length) } } C.fdb_future_release_memory(f.ptr) }) return f.v, f.e }
// GetWithError returns a database key or an error if the asynchronous operation // associated with this future did not successfully complete. The current // goroutine will be blocked until the future is ready. func (f FutureKey) GetWithError() (Key, error) { if f.k != nil { return f.k, nil } var value *C.uint8_t var length C.int fdb_future_block_until_ready(f.ptr) if err := C.fdb_future_get_key(f.ptr, &value, &length); err != 0 { if err == 2017 { return f.k, nil } else { return nil, Error(err) } } f.k = C.GoBytes(unsafe.Pointer(value), length) C.fdb_future_release_memory(f.ptr) return f.k, nil }