frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

JavaScript helper function for you to use

4•EGreg•7mo ago
Got a function that fetches some values asynchronously from somewhere? Consider wrapping it in this and making it a super-function.

Here is what it does for all the functions you wrap with it. In my experience, these are very helpful and also gives you a place you can even hook into and add more later (such as handling batching transparencly, etc):

Memoizes async getters: Call a function with the same arguments and it returns the cached result instead of recomputing.

Handles in-flight deduping: If multiple parts of your app call the same getter while it's still working, only one request is sent. The rest wait on the same promise.

Throttles concurrency: You can limit how many calls to your getter run in parallel. Useful for APIs, disk I/O, or anything rate-sensitive.

Supports custom caching backends: Pass any object with get, set, delete, and has. Works with Map, LRU, or your own cache logic.

Optional LRU eviction: If you pass a plain Map, it upgrades it to an LRU with a max size. Least recently used items are evicted when full.

Handles callbacks and Promises: Wraps traditional callback-style async functions, but gives you a modern Promise-based interface.

Smart-ish keying: Builds a cache key by stringifying non-function arguments. Works well for most everyday use cases.

Supports manual eviction: Call getter.forget(...args) to remove specific entries or getter.force(...args) to bypass the cache for one call.

Allows custom preparation logic: You can pass a prepare() function to clone or process cached results before using them.

  function createGetter(fn, {
    cache = new Map(),
    cacheSize = 100, // Used only if cache is a Map
    throttleSize = Infinity,
    prepare,
    callbackIndex,
    resolveWithFirstArgument = false
  } = {}) {
    const inFlight = new Map();
    let activeCount = 0;
    const queue = [];
  
    // Wrap Map in a simple LRU if needed
    if (cache instanceof Map) {
      const rawMap = cache;
      const lru = new Map();
  
      cache = {
        get(key) {
          if (!rawMap.has(key)) return undefined;
          const value = rawMap.get(key);
          lru.delete(key);
          lru.set(key, true); // Mark as most recently used
          return value;
        },
        set(key, value) {
          rawMap.set(key, value);
          lru.set(key, true);
          if (rawMap.size > cacheSize) {
            const oldest = lru.keys().next().value;
            rawMap.delete(oldest);
            lru.delete(oldest);
          }
        },
        delete(key) {
          rawMap.delete(key);
          lru.delete(key);
        },
        has(key) {
          return rawMap.has(key);
        }
      };
    }
  
    function makeKey(args) {
      return JSON.stringify(args.map(arg => (typeof arg === 'function' ? 'ƒ' : arg)));
    }
  
    function execute(context, args, key, resolve, reject) {
      const callback = (err, result) => {
        if (err) return reject(err);
        cache.set(key, [context, arguments]);
        if (prepare) prepare.call(null, context, arguments);
        resolve(resolveWithFirstArgument && context !== undefined ? context : result);
        processNext();
      };
  
      if (callbackIndex != null) args.splice(callbackIndex, 0, callback);
      else args.push(callback);
  
      if (fn.apply(context, args) === false) {
        cache.delete(key); // opt-out of cache
      }
    }
  
    function processNext() {
      activeCount--;
      if (queue.length && activeCount < throttleSize) {
        const next = queue.shift();
        activeCount++;
        execute(...next);
      }
    }
  
    const getter = function (...args) {
      return new Promise((resolve, reject) => {
        const context = this;
        const key = makeKey(args);
  
        if (cache.has(key)) {
          const [cachedContext, cachedArgs] = cache.get(key);
          if (prepare) prepare.call(null, cachedContext, cachedArgs);
          return resolve(resolveWithFirstArgument && cachedContext !== undefined ? cachedContext : cachedArgs[1]);
        }
  
        if (inFlight.has(key)) {
          return inFlight.get(key).then(resolve, reject);
        }
  
        const promise = new Promise((res, rej) => {
          if (activeCount < throttleSize) {
            activeCount++;
            execute(context, args.slice(), key, res, rej);
          } else {
            queue.push([context, args.slice(), key, res, rej]);
          }
        });
  
        inFlight.set(key, promise);
        promise.finally(() => {
          inFlight.delete(key);
        });
  
        promise.then(resolve, reject);
      });
    };
  
    getter.forget = (...args) => {
      const key = makeKey(args);
      inFlight.delete(key);
      return cache.delete(key);
    };
  
    getter.force = function (...args) {
      getter.forget(...args);
      return getter.apply(this, args);
    };
  
    return getter;
  }

Omarchy First Impressions

https://brianlovin.com/writing/omarchy-first-impressions-CEEstJk
1•tosh•33s ago•0 comments

Reinforcement Learning from Human Feedback

https://arxiv.org/abs/2504.12501
1•onurkanbkrc•1m ago•0 comments

Show HN: Versor – The "Unbending" Paradigm for Geometric Deep Learning

https://github.com/Concode0/Versor
1•concode0•1m ago•1 comments

Show HN: HypothesisHub – An open API where AI agents collaborate on medical res

https://medresearch-ai.org/hypotheses-hub/
1•panossk•5m ago•0 comments

Big Tech vs. OpenClaw

https://www.jakequist.com/thoughts/big-tech-vs-openclaw/
1•headalgorithm•7m ago•0 comments

Anofox Forecast

https://anofox.com/docs/forecast/
1•marklit•7m ago•0 comments

Ask HN: How do you figure out where data lives across 100 microservices?

1•doodledood•7m ago•0 comments

Motus: A Unified Latent Action World Model

https://arxiv.org/abs/2512.13030
1•mnming•8m ago•0 comments

Rotten Tomatoes Desperately Claims 'Impossible' Rating for 'Melania' Is Real

https://www.thedailybeast.com/obsessed/rotten-tomatoes-desperately-claims-impossible-rating-for-m...
2•juujian•9m ago•0 comments

The protein denitrosylase SCoR2 regulates lipogenesis and fat storage [pdf]

https://www.science.org/doi/10.1126/scisignal.adv0660
1•thunderbong•11m ago•0 comments

Los Alamos Primer

https://blog.szczepan.org/blog/los-alamos-primer/
1•alkyon•13m ago•0 comments

NewASM Virtual Machine

https://github.com/bracesoftware/newasm
1•DEntisT_•16m ago•0 comments

Terminal-Bench 2.0 Leaderboard

https://www.tbench.ai/leaderboard/terminal-bench/2.0
2•tosh•16m ago•0 comments

I vibe coded a BBS bank with a real working ledger

https://mini-ledger.exe.xyz/
1•simonvc•16m ago•1 comments

The Path to Mojo 1.0

https://www.modular.com/blog/the-path-to-mojo-1-0
1•tosh•19m ago•0 comments

Show HN: I'm 75, building an OSS Virtual Protest Protocol for digital activism

https://github.com/voice-of-japan/Virtual-Protest-Protocol/blob/main/README.md
4•sakanakana00•22m ago•0 comments

Show HN: I built Divvy to split restaurant bills from a photo

https://divvyai.app/
3•pieterdy•25m ago•0 comments

Hot Reloading in Rust? Subsecond and Dioxus to the Rescue

https://codethoughts.io/posts/2026-02-07-rust-hot-reloading/
3•Tehnix•25m ago•1 comments

Skim – vibe review your PRs

https://github.com/Haizzz/skim
2•haizzz•27m ago•1 comments

Show HN: Open-source AI assistant for interview reasoning

https://github.com/evinjohnn/natively-cluely-ai-assistant
4•Nive11•27m ago•6 comments

Tech Edge: A Living Playbook for America's Technology Long Game

https://csis-website-prod.s3.amazonaws.com/s3fs-public/2026-01/260120_EST_Tech_Edge_0.pdf?Version...
2•hunglee2•31m ago•0 comments

Golden Cross vs. Death Cross: Crypto Trading Guide

https://chartscout.io/golden-cross-vs-death-cross-crypto-trading-guide
2•chartscout•33m ago•0 comments

Hoot: Scheme on WebAssembly

https://www.spritely.institute/hoot/
3•AlexeyBrin•36m ago•0 comments

What the longevity experts don't tell you

https://machielreyneke.com/blog/longevity-lessons/
2•machielrey•37m ago•1 comments

Monzo wrongly denied refunds to fraud and scam victims

https://www.theguardian.com/money/2026/feb/07/monzo-natwest-hsbc-refunds-fraud-scam-fos-ombudsman
3•tablets•42m ago•1 comments

They were drawn to Korea with dreams of K-pop stardom – but then let down

https://www.bbc.com/news/articles/cvgnq9rwyqno
2•breve•44m ago•0 comments

Show HN: AI-Powered Merchant Intelligence

https://nodee.co
1•jjkirsch•47m ago•0 comments

Bash parallel tasks and error handling

https://github.com/themattrix/bash-concurrent
2•pastage•47m ago•0 comments

Let's compile Quake like it's 1997

https://fabiensanglard.net/compile_like_1997/index.html
2•billiob•48m ago•0 comments

Reverse Engineering Medium.com's Editor: How Copy, Paste, and Images Work

https://app.writtte.com/read/gP0H6W5
2•birdculture•53m ago•0 comments