client/operations.go
func (op *operation) AddHandler(function func(api.Operation)) (*EventTarget, error) {
	// Make sure we have a listener setup
	err := op.setupListener()
	if err != nil {
		return nil, err
	}

	// Make sure we're not racing with ourselves
	op.handlerLock.Lock()
	defer op.handlerLock.Unlock()

	// If we're done already, just return
	if op.StatusCode.IsFinal() {
		return nil, nil
	}

	// Wrap the function to filter unwanted messages
	wrapped := func(event api.Event) {
		newOp := api.Operation{}
		err := json.Unmarshal(event.Metadata, &newOp)
		if err != nil || newOp.ID != op.ID {
			return
		}

		function(newOp)
	}

	return op.listener.AddHandler([]string{"operation"}, wrapped)
}
func (op *operation) AddHandler(function func(api.Operation)) (*EventTarget, error) {
	// Make sure we have a listener setup
	err := op.setupListener()
	if err != nil {
		return nil, err
	}

	// Make sure we're not racing with ourselves
	op.handlerLock.Lock()
	defer op.handlerLock.Unlock()

	// If we're done already, just return
	if op.StatusCode.IsFinal() {
		return nil, nil
	}

	// Wrap the function to filter unwanted messages
	wrapped := func(event api.Event) {
		newOp := api.Operation{}
		err := json.Unmarshal(event.Metadata, &newOp)
		if err != nil || newOp.ID != op.ID {
			return
		}

		function(newOp)
	}

	return op.listener.AddHandler([]string{"operation"}, wrapped)
}
func ( op * operation ) AddHandler ( function func ( api . Operation ) ) ( * EventTarget , error ) { // Make sure we have a listener setup err := op . setupListener ( ) if err != nil { return nil , err } // Make sure we're not racing with ourselves op . handlerLock . Lock ( ) defer op . handlerLock . Unlock ( ) // If we're done already, just return if op . StatusCode . IsFinal ( ) { return nil , nil } // Wrap the function to filter unwanted messages wrapped := func ( event api . Event ) { newOp := api . Operation { } err := json . Unmarshal ( event . Metadata , & newOp ) if err != nil || newOp . ID != op . ID { return } function ( newOp ) } return op . listener . AddHandler ( [ ] string { " " } , wrapped ) }
// AddHandler adds a function to be called whenever an event is received
AddHandler adds a function to be called whenever an event is received