This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
) | |
func main() { | |
// Empty buffer (implements io.Writer) | |
var b bytes.Buffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func main() { | |
fmt.Fprintln(os.Stdout, "Hello Medium") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello Medium") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example to use Docker instead of containerd & nerdctl | |
# $ limactl start ./docker.yaml | |
# $ limactl shell docker docker run -it -v $HOME:$HOME --rm alpine | |
# To run `docker` on the host (assumes docker-cli is installed): | |
# $ export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock') | |
# $ docker ... | |
# This example requires Lima v0.8.0 or later | |
images: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import random | |
# A co-routine | |
async def add(x: int, y: int): | |
# function can do work between 1 second to 5 seconds | |
await asyncio.sleep(random.randrange(1, 5)) | |
return x + y | |
# Create a function to schedule co-routines on the event loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# A co-routine | |
async def add(x: int, y: int): | |
return x + y | |
# Create a function to schedule co-routines on the event loop | |
# then print results | |
async def get_results(): | |
inputs = [(2,3), (4,5), (5,5), (7,2)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# A co-routine | |
async def add(x: int, y: int): | |
return x + y | |
# Create a function to schedule tasks on the event loop | |
# then print results | |
async def get_results(): | |
inputs = [(2,3), (4,5), (5,5), (7,2)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# A co-routine | |
async def add(x: int, y: int): | |
return x + y | |
# Create a function to schedule co-routines on the event loop | |
# then print results | |
async def get_results(): | |
inputs = [(2,3), (4,5), (5,5), (7,2)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# A fast co-routine | |
async def add_fast(x, y): | |
print("starting fast add") | |
await asyncio.sleep(3) # Mimic some network delay | |
print("result ready for fast add") | |
return x + y | |
# A slow co-routine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# A co-routine | |
async def add(x: int, y: int): | |
return x + y | |
# Create a function to schedule co-routines on the event loop | |
# then print results and stop the loop | |
async def get_results(): | |
result1 = await add(3, 4) |