From ef69dfa646d6c63a2ffbf01fc859d6688150bf11 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 15 May 2022 12:40:30 -0400 Subject: [PATCH] refactor: Add 'table' subscription fns to generated proto services * Provides a simple convenience, as nearly all api subscriptions made on the front-end are converted to TableUpdates anyways * Can help reduce overhead by instantiating TableUpdate subscriptions lazily, and by using one internal TableUpdate subscription to provide notifications to all observers --- .../api/service_compiler/templates/c#/client.pb.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/api/service_compiler/templates/c#/client.pb.cs b/src/lib/api/service_compiler/templates/c#/client.pb.cs index 3825c2e70..3d2412ce4 100644 --- a/src/lib/api/service_compiler/templates/c#/client.pb.cs +++ b/src/lib/api/service_compiler/templates/c#/client.pb.cs @@ -10,14 +10,22 @@ namespace {{package}} { public sealed class {{name}} : IApiClient, IDisposable { readonly ClientChannel _channel; - {{name}}(ClientChannel channel) => + {{name}}(ClientChannel channel) { _channel = channel; + {{#each method}} + {{#if server_streaming}} + _{{name}}_tablei_src = new(() => subscribei_{{name}}().Table().Cache()); + {{/if}} + {{/each}} + } public void Dispose() => _channel.Dispose(); {{#each method}} {{#if server_streaming}} + readonly Lazy>> _{{name}}_tablei_src; + // {{comment}} public IObservable> subscribe_{{name}}(string qualifier = null) => _channel.subscribe<{{output_type_full}}, {{output_type_full}}>( @@ -29,6 +37,9 @@ namespace {{package}} { {{@index}}, "{{name}}", qualifier, {{output_type_full}}.Parser, a => ({{output_type_full}}Immutable)a) .reconstitute(_key); + public IObservable> subscribei_{{name}}_table(string qualifier = null) => + _{{name}}_tablei_src.Value; + static {{key_type.cstype}} _key({{output_type_full}} row) => row.{{camel key_field}};