or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Product Feed Processor

Build a real-time product feed processor that displays products progressively as they arrive from a streaming JSON API, without waiting for the complete response.

Requirements

Your implementation should:

  1. Fetch product data from a streaming JSON endpoint that returns a large array of products
  2. Process and display each product as soon as it arrives in the stream (not after the entire response completes)
  3. Extract product name and price from each product object as it becomes available
  4. Track the total number of products processed
  5. Handle the completion of the stream

The system should be efficient and responsive, showing products immediately as they stream in rather than blocking until all data has been received.

Expected Behavior

When streaming begins:

  • Products should be processed one at a time as they arrive
  • Each product should be immediately available for display/processing
  • The system should not wait for the complete JSON document before processing begins

When streaming completes:

  • Report the total count of products processed
  • Provide access to the fully parsed data structure

Implementation

@generates

API

/**
 * Processes a streaming JSON feed of products from the given URL.
 * Calls onProduct for each product as it arrives in the stream.
 * Calls onComplete when the entire feed has been processed.
 *
 * @param {string} url - The URL of the streaming JSON endpoint
 * @param {Function} onProduct - Callback invoked for each product: (product) => void
 * @param {Function} onComplete - Callback invoked when complete: (allProducts, count) => void
 * @returns {Object} Stream controller with an abort() method
 */
function processProductFeed(url, onProduct, onComplete) {
  // Implementation here
}

module.exports = { processProductFeed };

Test Cases

  • Given a URL returning {"products":[{"name":"Widget","price":10},{"name":"Gadget","price":20}]}, onProduct is called twice (once for each product) and onComplete is called with count 2 @test
  • Given a URL returning {"products":[]}, onComplete is called with count 0 and empty array @test
  • Given a URL returning {"products":[{"name":"Item A","price":5},{"name":"Item B","price":15},{"name":"Item C","price":25}]}, onProduct receives each product object progressively and onComplete receives all three products @test

Dependencies { .dependencies }

oboe { .dependency }

Provides streaming JSON parsing capabilities for progressive data processing.

@satisfied-by