Sharing an unfinished lookup can prevent two callers from making the same read at once. Keeping its rejected promise in the map forever creates a different behavior: every later caller inherits the old failure, even when a new attempt could succeed.
A Shopify 3PL adapter can share an in-flight read without turning it into a result cache. The same distinction applies to a drop shipping stock lookup. Remove the map entry when the promise settles, so the next call starts a new read.
Share only the pending operation
MDN documents finally() as cleanup after either fulfillment or rejection. Return the promise produced by finally(), so callers observe that promise's outcome rather than leaving a separate cleanup promise unhandled.
const assert = require('node:assert/strict'); function shareInFlight(load) { if (typeof load !== 'function') throw new TypeError('Loader required'); const pending = new Map(); return function read(key) { if (typeof key !== 'string' || key === '') { return Promise.reject(new TypeError('Scoped key required')); } if (pending.has(key)) return pending.get(key); const request = Promise.resolve().then(() => load(key)); const shared = request.finally(() => { if (pending.get(key) === shared) pending.delete(key); }); pending.set(key, shared); return shared; }; } async function test() { const calls = new Map(); const read = shareInFlight(key => { const attempt = (calls.get(key) || 0) + 1; calls.set(key, attempt); if (key === 'scoped-A' && attempt === 1) { throw new Error('Illustrative temporary read failure'); } return { key, attempt }; }); const first = read('scoped-A'); const same = read('scoped-A'); assert.equal(first, same); const failed = await Promise.allSettled([first, same]); assert.ok(failed.every(r => r.status === 'rejected')); assert.equal(calls.get('scoped-A'), 1); assert.deepEqual(await read('scoped-A'), { key: 'scoped-A', attempt: 2 }); const a = read('scoped-A'); const b = read('scoped-B'); assert.notEqual(a, b); assert.deepEqual(await Promise.all([a, b]), [ { key: 'scoped-A', attempt: 3 }, { key: 'scoped-B', attempt: 1 } ]); await assert.rejects(read(''), TypeError); await assert.rejects(read(null), TypeError); assert.throws(() => shareInFlight(null), TypeError); console.log('In-flight read cleanup checks passed'); } test().catch(error => { console.error(error); process.exitCode = 1; }); Save this as in-flight-read.cjs and run it with Node.js. The loader throws synchronously on the first scoped-A call. Both waiting callers receive a rejection from one attempt, then a later call succeeds. A further read starts a third attempt, showing that successful results are not retained either. Distinct keys have independent operations.
Keep the scope explicit
The caller must supply a key that distinguishes the account, warehouse and query context. The illustrative keys stand for already scoped identifiers. This is not permission to share stock data between accounts in a shopify fulfillment system.
This function has no timeout, automatic retry schedule or cancellation policy. An operation that never settles remains pending. Callers sharing a successful read also receive the same returned object and should treat it as read-only. Use this pattern for suitable reads, not order creation or other writes with side effects.
For a china fulfillment connection, validate those boundaries against the real interface. A hypothetical specification named International Fulfillment for Folligen would still need an actual access scope and read contract; that name does not establish a customer account or a working connector. Confirm the interface with the china 3PL before adapting the example.
YX Fulfillment's Shopify setup guide discusses the operational setup questions beyond this local JavaScript test.
Warehouse workstations and equipment.

