backpressure

rust
use std::sync::mpsc::{self, SyncSender};
use std::sync::{Arc, Mutex};
use std::thread;

mod worker;
use worker::{Message, Worker};

Bounded Thread Pool With Backpressure Using Rust Channels

threads concurrency channels
by codesnips 3 tabs
javascript
class TokenBucket {
  constructor(capacity, refillPerSecond) {
    this.capacity = capacity;
    this.refillPerMs = refillPerSecond / 1000;
    this.tokens = capacity;
    this.lastRefill = Date.now();

Token Bucket Rate Limiter Middleware for Express with Per-Key Buckets

nodejs express rate-limiting
by codesnips 4 tabs
javascript
const { WebSocketServer } = require('ws');
const crypto = require('crypto');

const wss = new WebSocketServer({ port: 8080 });

function broadcast(payload, except) {

Reconnecting WebSocket Chat Client with a Broadcasting Node Server

websocket realtime reconnection
by codesnips 3 tabs
rust
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::Mutex;
use tokio::time::sleep;

#[derive(Debug)]

Rate-Limiting Outbound HTTP with a Token Bucket in Rust (Tokio)

rust tokio rate-limiting
by codesnips 3 tabs
rust
use std::collections::HashSet;
use std::hash::Hash;

pub struct DedupByKey<I, K, F> {
    inner: I,
    key_fn: F,

Order-Preserving Stream Deduplication by Key in Rust with a HashSet Guard

rust streams deduplication
by codesnips 3 tabs
python
import os
import uuid

from flask import Blueprint, current_app, jsonify, request
from werkzeug.exceptions import RequestEntityTooLarge

Streaming Large Multipart File Uploads to Disk in Flask Without Buffering

flask werkzeug streaming
by codesnips 3 tabs
rust
use async_trait::async_trait;
use std::io;

#[async_trait]
pub trait ConnectionFactory: Send + Sync + 'static {
    type Connection: Send + 'static;

Building a Bounded Async Database Connection Pool With Tokio Semaphore

rust tokio async
by codesnips 3 tabs
go
package feed

import "time"

type Event struct {
	ID        string    `json:"id"`

Stream and Decode Newline-Delimited JSON (NDJSON) from an HTTP Response Body in Go

go ndjson streaming
by codesnips 3 tabs
java
@RestController
@RequestMapping("/api/transactions")
public class TransactionExportController {

    private final CsvExportService exportService;

Stream a Large CSV Export to the HTTP Response with StreamingResponseBody in Spring Boot

spring-boot streaming csv
by codesnips 3 tabs
javascript
function parseRange(header, size) {
  if (!header || !header.startsWith('bytes=')) return null;

  const [rawStart, rawEnd] = header.replace('bytes=', '').split('-');
  let start;
  let end;

HTTP Range Requests for Video Streaming in Node.js With fs.createReadStream

nodejs http streaming
by codesnips 3 tabs
rust
use std::sync::Arc;
use std::time::Duration;

use futures::stream::{FuturesUnordered, StreamExt};
use reqwest::Client;
use tokio::sync::Semaphore;

Bounded Concurrent HTTP Fan-Out With FuturesUnordered and Semaphore in Rust

rust async tokio
by codesnips 3 tabs
python
import csv


class _LineBuffer:
    def __init__(self):
        self._data = ""

Stream a Large CSV Export in Chunks from a Flask Endpoint

flask streaming csv
by codesnips 3 tabs