Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add reentrancy #993

Merged
merged 6 commits into from
Dec 20, 2023
Merged

add reentrancy #993

merged 6 commits into from
Dec 20, 2023

Conversation

qazwsxedckll
Copy link
Contributor

Two remaining problems.

  1. Users have to clone and copy protobuf/protoc-gen-go-grain/options/options.proto, in order to use options. grpc-gateway also uses this method.

  2. Users have to unmarshal *cluster.GrainResponse to response type when using reenterancy. I cannot find a place to do this automatically.

                f, err := client.InvokeServiceFuture(&InvokeServiceRequest{Name: "Bob"})
		ctx.ReenterAfter(f, func(resp interface{}, err error) {
			if err != nil {
				onError(err)
				return
			}

			switch msg := resp.(type) {
			case *cluster.GrainResponse:
				result := &InvokeServiceResponse{}
				err = proto.Unmarshal(msg.MessageData, result)
				if err != nil {
					onError(err)
				}
				respond(&InvokeServiceResponse{
					Message: req.Name + " from " + ctx.Identity() + " and " + result.Message,
				})
			case *cluster.GrainErrorResponse:
				onError(errors.New(msg.Err))
			default:
				onError(errors.New("unknown response"))
			}
		})

@rogeralsing
Copy link
Collaborator

@qazwsxedckll , we could get rid of GrainResponse completely. see #994

it is just a wrapper of the result message and don´t really bring any value

@qazwsxedckll qazwsxedckll force-pushed the dev branch 2 times, most recently from 743a59e to 5b43c0c Compare December 20, 2023 02:11
@rogeralsing
Copy link
Collaborator

This looks fantastic!

@qazwsxedckll
Copy link
Contributor Author

qazwsxedckll commented Dec 20, 2023

I suddenly realized that the respond and onError callback are not necessary. You can just call ctx.Respond() indise ctx.ReenterAfter(). I was just imitating the interface in dotnet.

@rogeralsing rogeralsing merged commit ca1d05b into asynkron:dev Dec 20, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants