BlockingQueue Take Plus DrainTo Batching
Block with take() for the first queued item, then coalesce all ready elements via drainTo in one consumer pass instead of spinning or polling.
Fetch remote data with typed success and error paths.
628 published examples — showing latest 48
Block with take() for the first queued item, then coalesce all ready elements via drainTo in one consumer pass instead of spinning or polling.
Stream structured regex matches from a Scanner with findAll(Pattern), extracting capture groups and byte offsets from MatchResult lazily.
Format start-to-end date spans with Intl.DateTimeFormat.formatRange to collapse shared months or years, and inspect segment sources via formatRangeToParts.
Wrap plain next() iterator objects with ES2025 Iterator.from so filter, map, and take chain lazily and stop pulling items once take hits its limit.
Transform Node Readable streams lazily with built-in filter, map, take, and toArray helpers so consumers pull only the records they need.
Canonicalize query strings with URLSearchParams.prototype.sort, which orders keys by UTF-16 code units while keeping duplicate key values in relative order.
Contrast NTILE bucketing against peer-aware CUME_DIST and interpolated PERCENTILE_CONT thresholds when latency samples share tied values.
Combine overlapping ROLLUP and GROUPING SETS clauses with PostgreSQL 14 GROUP BY DISTINCT so duplicate subtotal rows collapse cleanly.
Keep tenant unrolled with partial ROLLUP while using multi-argument GROUPING(region, category) bitmasks to tell real NULLs from subtotal rows.
Query JSONB with PostgreSQL 17 JSON_EXISTS, JSON_VALUE, and JSON_QUERY using PASSING variables, RETURNING types, and ON EMPTY/ON ERROR clauses.
Navigate nested JSONB with #> and #>>, test path existence with @?, and evaluate JSONPath boolean predicates directly using the @@ operator.
Merge group time windows into multiranges with range_agg and isolate shared overlap via range_intersect_agg across all rows in PostgreSQL.
Lockstep-zip heterogeneous set-returning functions with PostgreSQL ROWS FROM (...) WITH ORDINALITY, padding shorter streams with NULL safely.
Shred XML documents into typed relational columns with XMLTABLE, extracting attributes, defaults, NOT NULL checks, and FOR ORDINALITY numbers.
Render dates with ofLocalizedDate and FormatStyle, where the pattern itself comes from the formatter locale and FULL/LONG need a zone on the temporal.
Roll up grouped long metrics with Collectors.summarizingLong and LongSummaryStatistics, keeping count, sum, min, and max together per group.
flatMap expands each stream element into a sub-stream, generating ordered pair combinations or flattening nested lists in one pipeline.
Intl.Collator sensitivity climbs from base to variant: base folds case and accents, accent keeps accents, case keeps case, and variant distinguishes both.
Pull deep fields out in one statement with nested destructuring, rename bindings with colons, and combine defaults so missing API data cannot crash a render.
DateTimeFormat.formatToParts splits a formatted date into typed fields that reassemble into ISO stamps, and resolvedOptions reports the chosen locale rules.
A ReadableStream consumer calls reader.read() until done flips true, decoding each Uint8Array chunk with stream:true so multi-byte splits stay intact.
Inspect pg_matviews to see every materialized view, its owner, and refresh state, then compare with pg_views for plain views.
Read pg_stat_user_functions to see how often each PL/pgSQL function runs and how much time it consumes, gated by track_functions.
pg_typeof prints the real type of any expression, exposing literal surprises like unknown-typed strings and numeric results from floor(numeric).
A FROM-less SELECT evaluates one row of constant expressions, the quickest way to probe function output, casts, and operator semantics.
Intl.NumberFormat renders currency per locale and formatToParts splits the result into typed parts, so symbol, integer, and fraction render separately.
formatToParts yields Intl.DateTimeFormatPart objects that narrow on part.type, and resolvedOptions reports the exact locale, calendar, and hour cycle chosen.
navigator.connection exposes effectiveType, saveData and rtt on Chromium; feature-detect it, honor saveData first, then pick assets by measured network quality.
count(DISTINCT (user_id, day)) treats the row constructor as one key, separating unique pairs from plain row and column counts.
IN returns any-of matches; grouping joined tags and comparing HAVING count(DISTINCT tag) with the required count yields rows carrying every tag.
A recursive CTE walks nested jsonb children with jsonb_array_elements, tracking depth and path until every leaf array runs out.
Flatten a stream of streams with bridge: consume <-chan (<-chan T), drain each source under the same done, and yield one merged result channel.
StripPrefix removes a fixed path prefix before a FileServer, so static assets live under one URL subtree without moving files on disk.
io.NopCloser satisfies io.ReadCloser for a bare io.Reader; Close is a no-op and the underlying reader keeps its position after reads.
Each json.Encoder.Encode call appends a newline, so looping over records writes one compact JSON object per line that readers can parse row by row.
A custom io.Reader wraps another reader and rewrites each filled buffer in place, passing byte counts and EOF straight through so ReadAll composes.
Parse query strings with url.ParseQuery and surface malformed input: bare semicolons and invalid percent escapes return errors instead of dirty data.
Stream XML incrementally with xml.Decoder.Token: start elements, character data, and end elements arrive as you ask, without loading the whole tree.
Run one echo roundtrip over AsynchronousSocketChannel completion handlers while the main thread parks on a CountDownLatch until callbacks land.
A label on the outer loop lets break and continue jump out of both levels at once: search terminates on first hit, continue skips the whole row.
Locale.forLanguageTag parses BCP 47 tags and Locale.lookup picks the best match from user preferences, the same negotiation Accept-Language headers need.
Reverse all 64 bits or just the eight bytes of a long with Long.reverse and Long.reverseBytes for bit-order and endianness conversions without loops.
Flatten a nested tree depth-first with a recursive mapMulti helper that feeds each node straight downstream without building intermediate lists.
Loop read on a blocking SocketChannel until read() returns -1 for EOF, then echo back, with shutdownOutput closing the write half cleanly.
Turn a past Instant into human time ago labels, using Duration for minutes and hours and date arithmetic once a day has elapsed.
URLEncoder encodes query values with StandardCharsets.UTF_8 so spaces become plus signs and structural characters stay escaped in the query string.
Build cumulative weight bands on a TreeMap and hit them with ceilingEntry, so a random roll lands in the band its weight deserves.
Race several async generators through one merged iterator: each source keeps its own next() promise and Promise.any picks whichever settles first.
Showing 48 of 628 verified Data Fetching examples. Filter the full catalog by language, framework, or keyword in Explore.
Browse & filter all 628 examples in Explore →