This file contains 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 ( | |
"encoding/json" | |
"fmt" | |
) | |
type TenantProfileEntity struct { | |
SomeOtherValue string | |
} |
This file contains 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 ( | |
"errors" | |
"fmt" | |
"strconv" | |
"testing" | |
"github.com/stretchr/testify/require" | |
) |
This file contains 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
/* | |
This demonstrates a task scheduling loop where tasks can send back other tasks to the queue. | |
Program input: a nested list of items that can either be integers, or nested slices: | |
- when it's an integer, wait for 25 - value seconds | |
- when it's a slice, wait for len(slice) seconds, then put back each item in the queue to be processed next | |
waiting time simulates some processing, on which a concurrency limit is applied ( both waiting times share the same | |
limit ). pushing back to the queue should not be blocking. |
This file contains 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 ( | |
"errors" | |
"fmt" | |
) | |
type Example interface { | |
Init(config map[string]interface{}) | |
} |
This file contains 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 re | |
from sys import stdin | |
def main(): | |
result = "" | |
title_re = re.compile("^title (.*)$") | |
right_arrow_re = re.compile(r"(.+?)\s*(-?)->\s*(.+?)(:(.+))?$") | |
left_arrow_re = re.compile(r"(.+?)\s*<-(-?)\s*(.+?)(:(.+))?$") | |
empty = re.compile("^\s*$") |
This file contains 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
/* | |
This demonstrates a task scheduling loop where tasks can send back other tasks to the queue. | |
Program input: a nested list of items that can either be integers, or nested slices: | |
- when it's an integer, wait for 25 - value seconds | |
- when it's a slice, wait for len(slice) seconds, then put back each item in the queue to be processed next | |
waiting time simulates some processing, on which a concurrency limit is applied ( both waiting times share the same | |
limit ). pushing back to the queue should not be blocking. |
This file contains 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
""" | |
This demonstrates a task scheduling loop where tasks can send back other tasks to the queue. | |
Program input: a nested list of items that can either be integers, whose processing is simulated by waiting | |
a proportional amount of time, or another list, in which case after waiting a time proportional to its length, | |
sub-items are rescheduled for processing. | |
Solution is inspired by goroutines, channels and waitgroups. | |
Asyncio's Queue can serve both as channel and waitgroup, thanks to Queue.join() that blocks until the queue is empty. |
This file contains 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] | |
name = "processing_stream" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
futures = "0.3.24" | |
tokio = { version = "1.21.0", features = ["full"] } |
This file contains 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 | |
// Demonstrates how to constraint a generic type to implement an interface with a pointer receiver | |
// inspired by this SO answer: https://stackoverflow.com/a/71444968 | |
import ( | |
"fmt" | |
"strconv" | |
"strings" | |
) |
This file contains 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 | |
from typing import Awaitable, Callable, Coroutine, Iterator | |
from asyncio_pool import AioPool | |
import pytest as pytest | |
from more_itertools import peekable | |
""" | |
Different approaches to "How to limit concurrency with Python asyncio?" | |
https://stackoverflow.com/questions/48483348/how-to-limit-concurrency-with-python-asyncio/48484593#48484593 |
NewerOlder