// LockUnspentAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See LockUnspent for the blocking version and more details.
487058
func (c *Client) LockUnspentAsync(unlock bool, ops []*wire.OutPoint) FutureLockUnspentResult {
	outputs := make([]btcjson.TransactionInput, len(ops))
	for i, op := range ops {
		outputs[i] = btcjson.TransactionInput{
			Txid: op.Hash.String(),
			Vout: op.Index,
		}
	}
	cmd := btcjson.NewLockUnspentCmd(unlock, outputs)
	return c.sendCmd(cmd)
}
776079
func (c *Client) GetTransactionAsync(txHash *chainhash.Hash) FutureGetTransactionResult {
	hash := ""
	if txHash != nil {
		hash = txHash.String()
	}

	cmd := btcjson.NewGetTransactionCmd(hash, nil)
	return c.sendCmd(cmd)
}
1229977
func (c *Client) RPC(method string, args interface{}, resp interface{}) error {
	// Get a stream
	stream, err := c.Open()
	if err != nil {
		return fmt.Errorf("failed to open stream: %v", err)
	}
	defer stream.Close()
	stream.SetDeadline(time.Now().Add(rpcTimeout))

	// Create the RPC client
	cc := msgpackrpc.NewCodec(true, true, stream)
	return msgpackrpc.CallWithCodec(cc, method, args, resp)
}
940498
func FSSync(ctx context.Context, c session.Caller, opt FSSendRequestOpt) error {
	var pr *protocol
	for _, p := range supportedProtocols {
		if isProtoSupported(p.name) && c.Supports(session.MethodURL(_FileSync_serviceDesc.ServiceName, p.name)) {
			pr = &p
			break
		}
	}
	if pr == nil {
		return errors.New("no local sources enabled")
	}

	opts := make(map[string][]string)
	if opt.OverrideExcludes {
		opts[keyOverrideExcludes] = []string{"true"}
	}

	if opt.IncludePatterns != nil {
		opts[keyIncludePatterns] = opt.IncludePatterns
	}

	if opt.ExcludePatterns != nil {
		opts[keyExcludePatterns] = opt.ExcludePatterns
	}

	if opt.FollowPaths != nil {
		opts[keyFollowPaths] = opt.FollowPaths
	}

	opts[keyDirName] = []string{opt.Name}

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	client := NewFileSyncClient(c.Conn())

	var stream grpc.ClientStream

	ctx = metadata.NewOutgoingContext(ctx, opts)

	switch pr.name {
	case "tarstream":
		cc, err := client.TarStream(ctx)
		if err != nil {
			return err
		}
		stream = cc
	case "diffcopy":
		cc, err := client.DiffCopy(ctx)
		if err != nil {
			return err
		}
		stream = cc
	default:
		panic(fmt.Sprintf("invalid protocol: %q", pr.name))
	}

	return pr.recvFn(stream, opt.DestDir, opt.CacheUpdater, opt.ProgressCb, opt.Filter)
}
902857
func (c *Client) GetNetTotalsAsync() FutureGetNetTotalsResult {
	cmd := btcjson.NewGetNetTotalsCmd()
	return c.sendCmd(cmd)
}
951124
func NewAsynchConnection(spec *ConnectionSpec) (conn AsyncConnection, err Error) {
	defer func() {
		if e := recover(); e != nil {
			connerr := e.(error)
			err = newSystemErrorWithCause("NewSyncConnection", connerr)
		}
	}()

	//	var async *asyncConnHdl
	async := newAsyncConnHdl(spec)
	async.connect()
	async.startup()

	conn = async
	return
}
554791
func (c *Client) rpcConnListener() {
	// Make a channel for new connections.
	conns := make(chan *yamux.Session, 4)
	c.connPool.SetConnListener(conns)

	for {
		select {
		case <-c.shutdownCh:
			return
		case session, ok := <-conns:
			if !ok {
				continue
			}

			go c.listenConn(session)
		}
	}
}
503859
func (l *lockServer) RLock(args *dsync.LockArgs, reply *bool) error {
	l.mutex.Lock()
	defer l.mutex.Unlock()
	lrInfo := lockRequesterInfo{
		writer:        false,
		serverAddr:    args.ServerAddr,
		rpcPath:       args.ServiceEndpoint,
		uid:           args.UID,
		timestamp:     time.Now().UTC(),
		timeLastCheck: time.Now().UTC(),
	}
	if lri, ok := l.lockMap[args.Resource]; ok {
		if *reply = !isWriteLock(lri); *reply { // Unless there is a write lock
			l.lockMap[args.Resource] = append(l.lockMap[args.Resource], lrInfo)
		}
	} else { // No locks held on the given name, so claim (first) read lock
		l.lockMap[args.Resource] = []lockRequesterInfo{lrInfo}
		*reply = true
	}
	return nil
}
1146135
func (c *Client) ClientRPC(method string, args interface{}, reply interface{}) error {
	codec := &inmem.InmemCodec{
		Method: method,
		Args:   args,
		Reply:  reply,
	}
	if err := c.rpcServer.ServeRequest(codec); err != nil {
		return err
	}
	return codec.Err
}
880020
func (c *Conn) writeAsync(b []byte) (int, error) {
	// Prevent concurrent writes.
	c.buf.writeMu.Lock()
	defer c.buf.writeMu.Unlock()

	// Get the max buffer size to determine if the buffer's capacity
	// should be grown.
	c.buf.configMu.RLock()
	max := c.buf.max
	c.buf.configMu.RUnlock()

	// If the provided data is too large for the buffer then force
	// a synchrnous write.
	if max > 0 && len(b) > max {
		return c.writeSync(b)
	}

	// Lock access to the buffer. This prevents concurrent writes to
	// the buffer. Occasionally the lock is released temporarily to
	// check if the buffer's length allows this write operation to
	// proceed.
	c.buf.dataMu.Lock()

	// If the max buffer size is non-zero and larger than the
	// capacity of the buffer, then grow the buffer capacity.
	if max > 0 && max > c.buf.data.Cap() {
		c.buf.data.Grow(max)
	}

	// Wait until there is room in the buffer to proceed.
	for max > 0 && c.buf.data.Len()+len(b) > c.buf.data.Cap() {
		c.buf.dataMu.Unlock()
		c.buf.dataMu.Lock()
	}
	defer c.buf.dataMu.Unlock()

	// Write the data to the buffer.
	n, err := c.buf.data.Write(b)
	if err != nil {
		return n, err
	} else if n < len(b) {
		return n, fmt.Errorf("trunc write: exp=%d act=%d", len(b), n)
	}

	// Record the number of bytes written in a FIFO list.
	c.buf.dataN = append(c.buf.dataN, n)

	// Start a goroutine that reads n bytes from the buffer where n
	// is the first element in the FIFO list from above. The read
	// below may not actually correspond to the write from above;
	// that's okay. The important thing is the order of the reads,
	// and that's achieved using the circular buffer and FIFO list
	// of bytes written.
	go func() {
		// The read operation must also obtain a lock, preventing
		// concurrent access to the buffer.
		c.buf.dataMu.Lock()

		// Get the number of bytes to read.
		n := c.buf.dataN[0]
		c.buf.dataN = c.buf.dataN[1:]

		// Read the bytes from the buffer into a temporary buffer.
		b := make([]byte, n)
		if nr, err := c.buf.data.Read(b); err != nil {
			go func() { c.buf.errs <- err }()
			c.buf.dataMu.Unlock()
			return
		} else if nr < n {
			go func() {
				c.buf.errs <- fmt.Errorf("trunc read: exp=%d act=%d", n, nr)
			}()
			c.buf.dataMu.Unlock()
			return
		}

		// Ensure access to the buffer is restored.
		defer c.buf.dataMu.Unlock()

		// Write the temporary buffer into the underlying connection.
		if nw, err := c.writeSync(b); err != nil {
			go func() { c.buf.errs <- err }()
			return
		} else if nw < n {
			go func() {
				c.buf.errs <- fmt.Errorf("trunc write: exp=%d act=%d", n, nw)
			}()
			return
		}
	}()

	return n, nil
}
37214
func (sc *conn) PublishAsync(subject string, data []byte, ah AckHandler) (string, error) {
	return sc.publishAsync(subject, data, ah, nil)
}
202113
func (r *RPCWrapper) GetRPCClient(contextID string) (*RPCHdl, error) {

	r.Lock()
	defer r.Unlock()

	val, err := r.rpcClientMap.Get(contextID)
	if err != nil {
		return nil, err
	}

	return val.(*RPCHdl), nil
}
859762
func RPCClient(addr, auth string) (*client.RPCClient, error) {
	config := client.Config{Addr: addr, AuthKey: auth}
	return client.ClientFromConfig(&config)
}
1266011
func (cli *Client) SwarmGetUnlockKey(ctx context.Context) (types.SwarmUnlockKeyResponse, error) {
	serverResp, err := cli.get(ctx, "/swarm/unlockkey", nil, nil)
	defer ensureReaderClosed(serverResp)
	if err != nil {
		return types.SwarmUnlockKeyResponse{}, err
	}

	var response types.SwarmUnlockKeyResponse
	err = json.NewDecoder(serverResp.body).Decode(&response)
	return response, err
}
134850
func (oc *OpCommon) AddUnrefBlock(ptr data.BlockPointer) {
	oc.UnrefBlocks = append(oc.UnrefBlocks, ptr)
}
1129991
func bounceUnlocked(err error) error {
	if errors.Cause(err) == ErrUnlocked {
		return dependency.ErrBounce
	}
	return err
}
357602
func (i *IssueEvent) GetLockReason() string {
	if i == nil || i.LockReason == nil {
		return ""
	}
	return *i.LockReason
}