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
from typing import Type, Set, Any | |
from multiprocessing import Queue | |
import asyncio | |
class MulticastQueue: | |
def __init__(self, queue_constructor: Type[Queue] = Queue) -> None: | |
self.subscribers: Set[Queue] = set() | |
self.constructor = queue_constructor | |
def register(self) -> Queue: |
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
from queue import Queue | |
from threading import Thread | |
class KillSignal: | |
pass | |
class QueuePipe: | |
def __init__(self, queue_in: Queue, queue_out: Queue) -> None: |
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
from queue import Queue, Empty | |
from threading import Thread | |
from typing import Any | |
import time | |
class Ticker: | |
_alive = True | |
_q = Queue() | |
_stop_q = Queue() |
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
from queue import Queue | |
from threading import Thread | |
from typing import Any, List, Iterator | |
class PipeClose: | |
pass | |
class QueuePipe: |
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
interface Person { | |
name: string; | |
age: number; | |
height: number; | |
friends: Person[]; | |
} | |
// Jane implicitly implements the person type | |
const jane = { | |
name: "Jane", |
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
from typing import Sequence | |
from dataclasses import dataclass | |
@dataclass | |
class Person: | |
name: str | |
age: int | |
height: float | |
friends: Sequence[Person] | |
# in Python, unless using Protocols, variables must implement types explicitly |
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
type StringOrNumber = string | number; | |
const somethingGood: StringOrNumber = "123"; // ok! | |
const somethingBad: StringOrNumber = {}; // not ok! |
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
from typing import Union | |
StringOrNumber = Union[str, int] | |
something_good: StringOrNumber = "123" # ok! | |
something_bad: StringOrNumber = {} # not ok! |
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
type HasAge = { age: number }; | |
type HasName = { name: string }; | |
type HasNameAndAge = HasName & HasAge; | |
const correct: HasNameAndAge = { name: "Tim", age: 23 }; |
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
from dataclasses import dataclass | |
@dataclass | |
class HasAge: | |
age: int | |
@dataclass | |
class HasName: | |
name: str |