micaww / rage-rpc

A universal, asynchronous RPC implementation for RAGE Multiplayer
33 stars 20 forks source link

Multiple events with same name #19

Closed frrrht closed 4 years ago

frrrht commented 4 years ago

If you try and make multiple events with the same name, only the most recent one will be called. With normal Rage MP events this issue is not a thing.

mp.events.add('test_multi', () => {
    console.log('Output 1');
});

mp.events.add('test_multi', () => {
    console.log('Output 2');
});

rpc.register('rpc_test_multi', (args, info) => {
    console.log('Output 3');
});

rpc.register('rpc_test_multi', (args, info) => {
    console.log('Output 4');
});

mp.events.addCommand('output', (player) => {
    mp.events.call('test_multi');
    rpc.call('rpc_test_multi');
});

Result:

Output 1
Output 2
Output 4

Expected result:

Output 1
Output 2
Output 3
Output 4
micaww commented 4 years ago

This is intended. You can only register a single callback per procedure. This is how RPC works universally because the caller is expecting a response from a single remote machine. If there were multiple listeners, it wouldn't know which one to expect a response from.

If you want to have a bunch of listeners, use on/trigger instead. That will be have the same way as RAGE events, with the cross-environment benefits of rage-rpc. The only difference is you won't be able to get a response from it. It's more fire-and-forget.

If you wanted to get a response from multiple listeners, you would have to implement this yourself using register and your own callback registration and add all the results to the same array or something

frrrht commented 4 years ago

Awesome, thanks for the quick response! :)