Skip to content

Commit

Permalink
clientgen: more idiomatic empty return (encoredev#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredr authored Sep 4, 2024
1 parent bfa1ee2 commit 299686f
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/testdata/echo_client/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
10 changes: 5 additions & 5 deletions e2e-tests/testdata/echo_client/ts/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -892,10 +892,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
2 changes: 1 addition & 1 deletion internal/clientgen/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ class BaseClient {`)
}`)
}
js.WriteString(`
return;
return undefined;
}
`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -260,10 +260,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -389,7 +389,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
2 changes: 1 addition & 1 deletion internal/clientgen/testdata/goapp/expected_javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class BaseClient {
}

async getAuthData() {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
10 changes: 5 additions & 5 deletions internal/clientgen/testdata/goapp/expected_noauth_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -228,10 +228,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -320,7 +320,7 @@ class BaseClient {
}

async getAuthData(): Promise<CallParameters | undefined> {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
10 changes: 5 additions & 5 deletions internal/clientgen/testdata/goapp/expected_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -591,10 +591,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -720,7 +720,7 @@ class BaseClient {

return data;
}
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
2 changes: 1 addition & 1 deletion internal/clientgen/testdata/tsapp/expected_javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class BaseClient {
}

async getAuthData() {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class BaseClient {
}

async getAuthData() {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -230,10 +230,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -322,7 +322,7 @@ class BaseClient {
}

async getAuthData(): Promise<CallParameters | undefined> {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class BaseClient {
}

async getAuthData() {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
10 changes: 5 additions & 5 deletions internal/clientgen/testdata/tsapp/expected_stream_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -345,10 +345,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -437,7 +437,7 @@ class BaseClient {
}

async getAuthData(): Promise<CallParameters | undefined> {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
10 changes: 5 additions & 5 deletions internal/clientgen/testdata/tsapp/expected_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ export class StreamInOut<Request, Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -255,10 +255,10 @@ export class StreamIn<Response> {

async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}

async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -347,7 +347,7 @@ class BaseClient {
}

async getAuthData(): Promise<CallParameters | undefined> {
return;
return undefined;
}

// createStreamInOut sets up a stream to a streaming API endpoint.
Expand Down
6 changes: 3 additions & 3 deletions internal/clientgen/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,10 @@ func (ts *typescript) writeStreamClasses() {
receive := `
async next(): Promise<Response | undefined> {
for await (const next of this) return next;
return;
return undefined;
}
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void>{
async *[Symbol.asyncIterator](): AsyncGenerator<Response, undefined, void> {
while (true) {
if (this.buffer.length > 0) {
yield this.buffer.shift() as Response;
Expand Down Expand Up @@ -1108,7 +1108,7 @@ class BaseClient {
}

ts.WriteString(`
return;
return undefined;
}
`)

Expand Down

0 comments on commit 299686f

Please sign in to comment.