Skip to content

feat: transpile non-async Promise-returning methods with native async types#54

Merged
frosty00 merged 1 commit into
ccxt:masterfrom
carlotestor:non-async-promise-delegators
Jul 9, 2026
Merged

feat: transpile non-async Promise-returning methods with native async types#54
frosty00 merged 1 commit into
ccxt:masterfrom
carlotestor:non-async-promise-delegators

Conversation

@carlotestor

Copy link
Copy Markdown

Motivation

In ccxt pro, pure WS delegator methods in ts/src/pro/*.ts are declared without async but return Promise<T> directly, e.g.:

watchTickerInner(symbol: string, params = {}): Promise<any> {
    return this.watchMultiTickerInner('ticker', [symbol], params);
}

Because the transpiler only keys async behaviour off the async modifier, these methods currently transpile to uncompilable output in C#/Java/Go (raw Promise<T> return types / missing wrappers), which forces ccxt to carry a workaround that rewrites the sources to add async before transpiling (see ccxt#29122).

Changes

baseTranspiler now detects methods whose declared return type is Promise<T> even when the async modifier is absent, and the language transpilers emit the same wrapped signatures as for async methods:

  • C#: async Task / async Task<object>, with returned Promise expressions awaited
  • Java: CompletableFuture<T> with the existing async wrapper
  • Go: <-chan with the existing channel wrapper

Sync methods without a Promise return type are unaffected.

Testing

  • New unit tests in tests/csharpTranspiler.test.ts, tests/goTranspiler.test.ts, tests/javaTranspiler.test.ts covering non-async Promise-returning delegators (single-line and multi-line bodies), verifying output is byte-identical to the equivalent async declaration
  • Full suite passes: 133/133 across the three affected test files, and npm run test passes overall
  • Verified end-to-end against ccxt: transpiled all pro exchanges with this patch and compared with the current build/reAsyncDelegators.ts workaround — generated C#/Java/Go files are byte-identical, so the ccxt-side workaround can be deleted

dist/ was intentionally left untouched (following recent PRs where generated files are updated separately).

… types

Methods declared without 'async' but returning Promise<T> (e.g. pure WS
delegators in ccxt pro) were previously transpiled with raw Promise<T>
return types in C#/Java/Go, producing uncompilable output. Now they are
detected via the declared return type and emitted with the same wrapped
signatures as async methods:

- C#:   async Task / async Task<object> (+ awaited return expressions)
- Java: CompletableFuture<T> with the async wrapper
- Go:   <-chan with the channel wrapper

Sync methods without a Promise return type are unaffected.
@carlotestor
carlotestor force-pushed the non-async-promise-delegators branch from dee655c to 232cabf Compare July 9, 2026 10:08
@carlotestor

Copy link
Copy Markdown
Author

All tests passing on the latest commit (232cabf):

Test Suites: 8 passed, 8 total
Tests:       362 passed, 362 total
Snapshots:   0 total
Time:        39.909 s

This includes the 133 tests across the C#, Java and Go transpiler suites that specifically exercise the new non-async Promise-returning delegator handling — each one asserts the transpiled output is byte-identical to what the classic async/await form produces, so downstream generated exchange files in ccxt are unaffected.

Also verified end-to-end against ccxt: transpiling all pro exchange files with this branch produces output identical to master + the current build/reAsyncDelegators.ts workaround, which this PR makes removable.

@frosty00
frosty00 merged commit d2d92a3 into ccxt:master Jul 9, 2026
1 check 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