示例#1
0
// 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
}
示例#2
0
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
}