Skip to content
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

Write Durable Objects in Go #29

Open
eliezedeck opened this issue Apr 5, 2023 · 2 comments
Open

Write Durable Objects in Go #29

eliezedeck opened this issue Apr 5, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@eliezedeck
Copy link

Hi,

First of all, I'd like to express my thanks and my encouragement for the folks behind this project. I think this deserve full support from Cloudflare.

Now, I seem to have noticed that the Durable Objects can only be written in JS. I'd like to know if there is a plan to support writing actual DurableObject classes using Go itself, and not just the ability to call the stub from Go.

Thank you.

@syumai
Copy link
Owner

syumai commented Apr 5, 2023

Hi, @eliezedeck !

Thank you for your feedback. In conclusion, I believe it is possible. However, the implementation will require one of the following two patterns.

  1. write a small amount of JavaScript code.
  2. generate JavaScript code.

In either case, due to the nature of Durable Objects, JavaScript code is required.

Durable Objects must be declared and exported as a JavaScript class.
https://developers.cloudflare.com/workers/learning/using-durable-objects/#configuring-durable-object-bindings

The problem with this is that it relies on the ES module.

In the case of Pattern 1, it is likely that the following short code would need to be added to the JavaScript:
(The following example assumes that the class name is Counter)

import { createDurableObjectClass } from "./utils.mjs";

export const Counter = createDurableObjectClass("Counter");

For pattern 2, I would provide the workers command as a CLI tool to automatically generate the current worker.mjs file.

$ workers generate .

Pattern 1 needs to be investigated to see if it can be implemented. Hopefully, this will be a relatively lightweight implementation since there is no need to provide a CLI tool. However, some additional work will be required to wrap the functionality provided by Durable Objects.

Pattern 2 can certainly be implemented. However, the hurdle for implementing a "worker" may be somewhat higher because of the code generation required; wrapping the functionality provided by Durable Objects would require the same amount of extra work as Pattern 1.

In any case, it seems difficult to achieve this immediately. I'll put it on the wish list!
Thank you.

cc: @akarasz

@syumai syumai added the enhancement New feature or request label Apr 5, 2023
@eliezedeck
Copy link
Author

Thank you for the details explanation @syumai. I hope it'll be possible, hopefully one day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants