async

rust
use std::time::Duration;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct BackoffPolicy {
    pub base_delay: Duration,

Exponential Backoff With Jitter for Retrying Fallible Async Operations in Rust

rust tokio async
by codesnips 3 tabs
typescript
import { useEffect, useState } from "react";

export function useDebouncedValue<T>(value: T, delay = 300): T {
  const [debounced, setDebounced] = useState<T>(value);

  useEffect(() => {

Debounced Search Box With AbortController to Cancel Stale Fetches in React

react hooks debounce
by codesnips 3 tabs
rust
use std::time::Duration;
use tokio_util::sync::CancellationToken;

pub struct Worker {
    id: usize,
    token: CancellationToken,

Graceful Task Shutdown in Tokio Using CancellationToken

tokio async cancellation
by codesnips 3 tabs
java
@Configuration
@EnableAsync
public class AsyncConfig {

    @Bean(name = "orderExecutor")
    public ThreadPoolTaskExecutor orderExecutor() {

Debouncing Order Recalculations with Spring @Async and a Configured ThreadPoolTaskExecutor

spring-boot async thread-pool
by codesnips 3 tabs
php
<?php

namespace App\Entity;

trait RecordsEvents
{

Dispatch Domain Events After Doctrine Flush with a postFlush Subscriber in Symfony

symfony doctrine messenger
by codesnips 4 tabs
java
package com.shop.orders.events;

import java.math.BigDecimal;
import java.time.Instant;

public record OrderPlacedEvent(

Transactional Domain Events With Spring's ApplicationEventPublisher and @TransactionalEventListener

spring spring-boot domain-events
by codesnips 4 tabs
rust
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum WebhookEvent {
    #[serde(rename = "payment.succeeded")]

Tagged Webhook Deserialization and Typed Handler Dispatch in Rust with Serde

webhooks serde axum
by codesnips 3 tabs
rust
use axum::{
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},
    response::{IntoResponse, Response},
    Json,
};

Axum Bearer Token Extractor with Shared Auth State and Typed Claims

axum authentication middleware
by codesnips 3 tabs
python
import enum
import datetime as dt

from sqlalchemy import Column, Integer, String, BigInteger, Enum, DateTime
from sqlalchemy.orm import declarative_base

Streaming FastAPI File Uploads with a Background Validation Task

fastapi uploads background-tasks
by codesnips 3 tabs
typescript
import { useForm } from 'react-hook-form'
import { useState } from 'react'
import api from '@/services/api'

interface SignupFormData {
  email: string

React Hook Form with async validation

react forms validation
by Maya Patel 1 tab
typescript
export type FetchState<T> =
  | { status: 'idle' }
  | { status: 'loading' }
  | { status: 'success'; data: T }
  | { status: 'error'; error: Error };

Discriminated-Union State Machine for a React Data-Fetching Hook

react hooks state-machine
by codesnips 3 tabs
python
from celery import shared_task
from django.core.mail import send_mail
from django.contrib.auth import get_user_model

User = get_user_model()

Django celery task for async email sending

django python celery
by Priya Sharma 2 tabs