Skip to content

feat: close a resource at the end of async with - #94

Closed
moetemp wants to merge 1 commit into
moe/up/varargs-unwrap-result-fieldfrom
moe/up/resource-close
Closed

moetemp wants to merge 1 commit into
moe/up/varargs-unwrap-result-fieldfrom
moe/up/resource-close

Conversation

@moetemp

@moetemp moetemp commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

What changed?

This PR adds @nexus.close, which marks the method that ends a resource, so async with closes it.

/// @nexus.operation "close-stream"
/// @nexus.close
close: func();
  • Python's resource class gets __aenter__ and __aexit__. At the end of the block, _support.exit_close(self, exc) decides if it closes. The close method's parameters must be optional, since the block's end passes none.
  • An operation that returns such a resource returns a ResourceCall, which nexgen writes in _resource_call.py. So await client.create_stream(...) and async with client.create_stream(...) both work.

TypeScript and .NET get [Symbol.asyncDispose] and IAsyncDisposable in a follow-up PR.

Why?

The proposal creates a Stream in async with, and the end of the block closes it. A close carries no value. The support package decides the policy, since Workflow code can keep a Stream open for a retry run.

How did you test it?

Link to a test plan if any -

  • Unit Tests
  • Staging
  • End to End Tests

Python tests close a Stream after a clean, a failed and a canceled block. A Workflow block leaves the close to the run.

@moetemp
moetemp force-pushed the moe/up/resource-close branch from db96631 to 4f19dc9 Compare October 29, 2026 04:00
@moetemp
moetemp force-pushed the moe/up/resource-close branch from 4f19dc9 to db18952 Compare October 31, 2026 13:08
@moetemp
moetemp force-pushed the moe/up/resource-close branch 2 times, most recently from 99765ef to 7e9445a Compare November 4, 2026 09:34
@moetemp
moetemp changed the base branch from moe/up/poll-items to moe/up/varargs-unwrap-result-field November 4, 2026 09:35
@moetemp
moetemp force-pushed the moe/up/varargs-unwrap-result-field branch from 00292fd to e3ee76c Compare November 5, 2026 05:19
@moetemp
moetemp force-pushed the moe/up/resource-close branch 2 times, most recently from 5b9ed4e to 95b18f5 Compare November 5, 2026 07:27
@moetemp
moetemp force-pushed the moe/up/varargs-unwrap-result-field branch from e3ee76c to 08c1907 Compare November 5, 2026 07:27
`@nexus.close` marks the method that ends a resource. Python closes it at a block's end, and a
call that returns it returns a `ResourceCall` that nexgen emits.
@moetemp
moetemp force-pushed the moe/up/resource-close branch from 95b18f5 to c7e5e39 Compare November 5, 2026 22:22
@moetemp
moetemp force-pushed the moe/up/varargs-unwrap-result-field branch from 08c1907 to 6b54092 Compare November 5, 2026 22:22
@moetemp

moetemp commented Nov 6, 2026

Copy link
Copy Markdown
Owner Author

Moved to temporalio#369, on main.

@moetemp moetemp closed this Nov 6, 2026
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.

1 participant