Skip to content

Commit 3625ce7

Browse files
authored
Add quickstart to README (#999)
* adding quickstart instructions to the README * Update README.md * Update README.md * fix: close Python code block and add working example link The Python code block was missing its closing backticks, causing the markdown parser to treat the rest of the file as code. Also added the working example link to match the TypeScript section.
1 parent 9a47f1c commit 3625ce7

File tree

3 files changed

+147
-12
lines changed

3 files changed

+147
-12
lines changed

README.md

Lines changed: 147 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![resonate component banner](/assets/resonate-component.png)
1+
![resonate banner](/assets/resonate-banner.png)
22

33
# Resonate Server
44

@@ -18,27 +18,162 @@ To provide those abstractions at the application level (i.e. to enable API-like
1818

1919
The Resonate Server is a highly efficient single binary that pairs with a Resonate SDK to provide those APIs.
2020

21-
### [How to contribute to this repo](./CONTRIBUTING.md)
21+
- [How to contribute to this repo](./CONTRIBUTING.md)
22+
- [Evaluate Resonate for your next project](https://docs.resonatehq.io/evaluate/)
23+
- [Example application library](https://github.com/resonatehq-examples)
24+
- [The concepts that power Resonate](https://www.distributed-async-await.io/)
25+
- [Join the Discord](https://resonatehq.io/discord)
26+
- [Subscribe to the Blog](https://journal.resonatehq.io/subscribe)
27+
- [Follow on Twitter](https://twitter.com/resonatehqio)
28+
- [Follow on LinkedIn](https://www.linkedin.com/company/resonatehqio)
29+
- [Subscribe on YouTube](https://www.youtube.com/@resonatehqio)
2230

23-
### [Get started with Resonate](https://docs.resonatehq.io/get-started/)
31+
## Resonate quickstart
2432

25-
### [Evaluate Resonate for your next project](https://docs.resonatehq.io/evaluate/)
33+
![resonate quickstart banner](./assets/quickstart-banner.png)
2634

27-
### [Example application library](https://github.com/resonatehq-examples)
35+
### 1. Install the Resonate Server & CLI
2836

29-
### [The concepts that power Resonate](https://www.distributed-async-await.io/)
37+
```shell
38+
brew install resonatehq/tap/resonate
39+
```
40+
41+
### 2. Install the Resonate SDK
3042

31-
### [Join the Discord](https://resonatehq.io/discord)
43+
#### TypeScript
3244

33-
### [Subscribe to the Blog](https://journal.resonatehq.io/subscribe)
45+
```shell
46+
npm install @resonatehq/sdk
47+
```
3448

35-
### [Follow on Twitter](https://twitter.com/resonatehqio)
49+
#### Python
50+
51+
```shell
52+
pip install resonate-sdk
53+
```
54+
55+
### 3. Write your first Resonate Function
56+
57+
A countdown as a loop. Simple, but the function can run for minutes, hours, or days, despite restarts.
58+
59+
#### TypeScript (countdown.ts)
60+
61+
```typescript
62+
import { Resonate, type Context } from "@resonatehq/sdk";
63+
64+
function* countdown(context: Context, count: number, delay: number) {
65+
for (let i = count; i > 0; i--) {
66+
// Run a function, persist its result
67+
yield* context.run((context: Context) => console.log(`Countdown: ${i}`));
68+
// Sleep
69+
yield* context.sleep(delay * 1000);
70+
}
71+
console.log("Done!");
72+
}
73+
// Instantiate Resonate
74+
const resonate = new Resonate({ url: "http://localhost:8001" });
75+
// Register the function
76+
resonate.register(countdown);
77+
```
78+
79+
[Working example](https://github.com/resonatehq-examples/example-quickstart-ts)
80+
81+
#### Python (countdown.py)
82+
83+
```python
84+
from resonate import Resonate, Context
85+
from threading import Event
86+
87+
# Register the function
88+
@resonate.register
89+
def countdown(ctx: Context, count: int, delay: int):
90+
for i in range(count, 0, -1):
91+
# Run a function, persist its result
92+
yield ctx.run(ntfy, i)
93+
# Sleep
94+
yield ctx.sleep(delay)
95+
print("Done!")
96+
97+
98+
def ntfy(_: Context, i: int):
99+
print(f"Countdown: {i}")
100+
101+
102+
# Instantiate Resonate
103+
resonate = Resonate.remote()
104+
resonate.start() # Start Resonate threads
105+
Event().wait() # Keep the main thread alive
106+
```
107+
108+
[Working example](https://github.com/resonatehq-examples/example-quickstart-py)
109+
110+
### 4. Start the server
111+
112+
```shell
113+
resonate dev
114+
```
36115

37-
### [Follow on LinkedIn](https://www.linkedin.com/company/resonatehqio)
116+
### 5. Start the worker
117+
118+
#### TypeScript
119+
120+
```shell
121+
npx ts-node countdown.ts
122+
```
123+
124+
#### Python
125+
126+
```shell
127+
python countdown.py
128+
```
129+
130+
### 6. Activate the function
131+
132+
Activate the function with execution ID `countdown.1`:
133+
134+
```shell
135+
resonate invoke countdown.1 --func countdown --arg 5 --arg 60
136+
```
137+
138+
### 7. Result
139+
140+
You will see the countdown in the terminal
141+
142+
#### TypeScript
143+
144+
```shell
145+
npx ts-node countdown.ts
146+
Countdown: 5
147+
Countdown: 4
148+
Countdown: 3
149+
Countdown: 2
150+
Countdown: 1
151+
Done!
152+
```
153+
154+
#### Python
155+
156+
```shell
157+
python countdown.py
158+
Countdown: 5
159+
Countdown: 4
160+
Countdown: 3
161+
Countdown: 2
162+
Countdown: 1
163+
Done!
164+
```
165+
166+
### What to try
167+
168+
After starting the function, inspect the current state of the execution using the `resonate tree` command. The tree command visualizes the call graph of the function execution as a graph of durable promises.
169+
170+
```shell
171+
resonate tree countdown.1
172+
```
38173

39-
### [Subscribe on YouTube](https://www.youtube.com/@resonatehqio)
174+
Now try killing the worker mid-countdown and restarting. **The countdown picks up right where it left off without missing a beat.**
40175

41-
## Server quick start instructions
176+
## More ways to install the server
42177

43178
For more Resonate Server deployment information see the [Set up and run a Resonate Server](https://docs.resonatehq.io/operate/run-server) guide.
44179

assets/quickstart-banner.png

31.3 KB
Loading

assets/resonate-banner.png

69 KB
Loading

0 commit comments

Comments
 (0)