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

Idea: RPC system #15

Open
stelcheck opened this issue Apr 6, 2018 · 3 comments
Open

Idea: RPC system #15

stelcheck opened this issue Apr 6, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@stelcheck
Copy link
Member

stelcheck commented Apr 6, 2018

Note: will flesh out a complete pseudo-code in upcoming weeks.

Based on messages definition, allow for a request/reply type of API.

  1. Should not interfere with messages (e.g. how will harmonize with MessageType.parse?)
  2. Should provide a very lightweight encapsulation
  3. Network-agnostic: for instance, I should be able to make RPC calls go from the server to the client
  4. Timeouts should be possible (e.g timing out requests)

shared/messages/index.ts

// [...]

export enum ServiceIds {
  ServerService
}

// Todo: export decorator?

shared/messages/services/ServerService.ts

import { ServiceIds, Service } from '../'
import MessageRPCService, { RPCResponse } from 'megadata/classes/MessageRPCService'

@Service(ServiceIds.ServerService)
abstract class ServerService extends MessageRPCService {
  public SomeCall(message: MessageType): ReturnMessage;
}
@stelcheck stelcheck added the enhancement New feature or request label Apr 6, 2018
@stelcheck
Copy link
Member Author

stelcheck commented Apr 6, 2018

Or maybe...

server

// Todo: AutoloadRpc?
@Service(ServerService, Server)
class extends MessageEmitter {
  @RPC(ServerService.Something)
  public SomeCall(message: MessageType): RPCResponse<ReturnMessage> {
    // ...
  }
}

client

const serverService = new RPCService(ServerService)
const returnMessage = await serverService.SomeCall(message) // can throw on error messages!

@yovanoc
Copy link

yovanoc commented Apr 29, 2018

I'm interested in doing this but I have some questions first :
What is the main goal of this?
Can I have more information about what is exactly wanted or some pseudo-code?
Thanks

@stelcheck
Copy link
Member Author

This one will likely be hard to get done before #12 is done, but the idea is: there are some case where you may want the client and server to be in lockstep, e.g. send a message, wait for a reply (or at least for the server to confirm some processing has been completed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants