Skip to content

Instantly share code, notes, and snippets.

View ChristianIvicevic's full-sized avatar
🌴
On vacation

Christian Ivicevic ChristianIvicevic

🌴
On vacation
View GitHub Profile
/**
* Rejects any promise after the specified amount of time (in ms). Useful for
* timing out long-running operations that didn't resolve in time.
* @param promise Promise to race against.
* @param timeout Time in ms to wait until rejecting the promise unless it
* resolved in time.
* @return A new promise that either behaves like the original promise or
* rejects after the specified amount of time.
*/
export const racePromise = async <T>(promise: Promise<T>, timeout: number) => {
class TcpConnection : public std::enable_shared_from_this<TcpConnection> {
public:
auto start() -> void {
// (1) Redudant declaration of paramters and types
asio::async_write(
Socket, asio::buffer(Response),
[This = shared_from_this()](const asio::error_code &ErrorCode,
size_t TransferredBytes) -> void {
This->handleWrite(ErrorCode, TransferredBytes);
});
type Class<T = unknown, Arguments extends unknown[] = unknown[]> = new (
...args: Arguments
) => T;
const nameof = <T>(name: keyof T) => name;
type Builder<T> = {
[K in keyof Omit<
T,
{
/* eslint-disable no-console */
import {isEqual, isPlainObject} from 'lodash';
import {useEffect, useRef} from 'react';
type Options = Partial<{
/**
* String prefix used to distinguish multiple groups.
*/
groupName: string;
/**