Beispiel #1
0
// queryToIter takes a FinalizedQuery and returns an iterator function which
// will produce either *items or errors.
//
//  - d is the raw datastore to run this query on
//  - filter is a function which will return true if the given key should be
//    excluded from the result set.
func queryToIter(stopChan chan struct{}, fq *ds.FinalizedQuery, d ds.RawInterface) func() (*item, error) {
	c := make(chan *item)

	go func() {
		defer close(c)

		err := d.Run(fq, func(k *ds.Key, pm ds.PropertyMap, _ ds.CursorCB) error {
			i := &item{key: k, data: pm}
			select {
			case c <- i:
				return nil
			case <-stopChan:
				return ds.Stop
			}
		})
		if err != nil {
			c <- &item{err: err}
		}
	}()

	return func() (*item, error) {
		itm := <-c
		if itm == nil {
			return nil, nil
		}
		if itm.err != nil {
			return nil, itm.err
		}
		return itm, nil
	}
}
Beispiel #2
0
func doRunInTransaction(base ds.RawInterface, f func(context.Context) error, opts *ds.TransactionOptions) error {
	return base.RunInTransaction(func(ctx context.Context) error {
		return withTxnBuf(ctx, f, opts)
	}, opts)
}