Skip to content

Instantly share code, notes, and snippets.

@wvteijlingen
wvteijlingen / RetryStrategy.swift
Last active March 4, 2024 17:10
Swift RetryStrategy
public protocol RetryStrategy {
/// True if the strategy allows to retry a failed action. False if all the retries have been 'used up'.
var shouldRetry: Bool { get }
/// The delay for which to wait before attempting to retry a failed action.
var delay: TimeInterval { get }
/// Returns a copy of this retry strategy with the number of allowable retries lowered by one.
var consumedOnce: Self { get }
}
@wvteijlingen
wvteijlingen / WebSocket.swift
Last active July 2, 2023 10:49
Swift WebSocket that uses AsyncThrowingStream
import Foundation
import Combine
public enum WebSocketError: Swift.Error {
case alreadyConnectedOrConnecting
case notConnected
case cannotParseMessage(String)
}
public extension WebSocket {
@wvteijlingen
wvteijlingen / Component.tsx
Created May 7, 2024 09:07
React Native Dark Mode
import useThemedStyles, { createThemedStyleSheet } from "./useThemedStyles"
export default function Component() {
const [styles, colorScheme] = useThemedStyles(stylesheet)
// ...
}
const stylesheet = createThemedStyleSheet((theme) => ({
container: {
backgroundColor: theme.colors.background