Skip to content

Implements Spawn in Go and TS #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Implements Spawn in Go and TS #12

wants to merge 29 commits into from

Conversation

luiscape
Copy link
Member

@luiscape luiscape commented May 7, 2025

The Go SDK now supports spawn as follows:

function, err := modal.FunctionLookup(
	context.Background(),
	"libmodal-test-support", "echo_string", modal.LookupOptions{},
)

// Call function using spawn
functionCall, err := function.Spawn(nil, map[string]any{"s": "hello"})

// Get input later
result, err := functionCall.Get(modal.FunctionCallGetOptions{})

// Or cancel Function Call
result, err := functionCall.Cancel(modal.FunctionCallCancelOptions{})

Internally, Remote() is effectively the same as Spawn() + Get().

Equivalent TS implementation:

import { Function_ } from "modal";

const echo = await Function_.lookup("libmodal-test-support", "echo_string");

// Spawn the function with kwargs.
const functionCall = await echo.spawn([], { s: "Hello world!" });
const ret = await functionCall.get();

@luiscape luiscape requested review from ekzhang and gongy May 7, 2025 14:36
@luiscape luiscape self-assigned this May 7, 2025
Copy link
Member

@ekzhang ekzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specific review comments are below, but there are a couple general style changes that I think would make it a better library:

  • Follow doc comment conventions: complete sentences, and start with the name of the item being described. https://tip.golang.org/doc/comment
  • Fix typos and incomplete comments that trailed off
  • Use %w for Go errors instead of %v

These should be pretty quick changes though. After that, happy to collaborate on porting to JS and then we can merge both together.

@luiscape
Copy link
Member Author

luiscape commented May 8, 2025

@ekzhang thanks for the review. Let me know what you think now.

@luiscape luiscape requested a review from ekzhang May 8, 2025 02:33
Copy link
Member

@ekzhang ekzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@luiscape luiscape changed the title Implements Spawn in the Go SDK Implements Spawn in Go and TS May 16, 2025
@luiscape luiscape requested a review from ekzhang May 16, 2025 19:55
@luiscape
Copy link
Member Author

@ekzhang can you take another look? My latest changes implement timeout following our conventions and using the implementation from the Python SDK as reference.

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