This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
    • t
      t
    • t
      value
    • v
      next
    • v
      forEach
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Asynciterator

    AsyncIterator

    Bindings to async iterators, a way to do async iteration in JavaScript.

    See async iterator protocols on MDN.

    t

    RESCRIPT
    type t<'a>

    The type representing an async iterator.

    value

    RESCRIPT
    type value<'a> = {done: bool, value: option<'a>}

    next

    RESCRIPT
    let next: t<'a> => promise<value<'a>>

    next(asyncIterator)

    Returns the next value of the iterator, if any.

    See async iterator protocols on MDN.

    Examples

    • A simple example, getting the next value:

    RESCRIPT
    @val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator" let {AsyncIterator.done, value} = await asyncIterator->AsyncIterator.next
    • Complete example, including looping over all values:

    RESCRIPT
    // Let's pretend we get an async iterator returning ints from somewhere. @val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator" let processMyAsyncIterator = async () => { // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. let break = ref(false) while !break.contents { // Await the next iterator value let {value, done} = await asyncIterator->AsyncIterator.next // Exit the while loop if the iterator says it's done break := done // This will log the (int) value of the current async iteration, if a value was returned. Console.log(value) } }

    forEach

    RESCRIPT
    let forEach: (t<'a>, option<'a> => unit) => promise<unit>

    forEach(iterator, fn) consumes all values in the async iterator and runs the callback fn for each value.

    See iterator protocols on MDN.

    Examples

    RESCRIPT
    // Let's pretend we get an async iterator returning ints from somewhere. @val external asyncIterator: AsyncIterator.t<int> = "someAsyncIterator" await asyncIterator->AsyncIterator.forEach(value => switch value { | Some(value) if value > 10 => Console.log("More than 10!") | _ => () } )
    Types and values
    • t
      t
    • t
      value
    • v
      next
    • v
      forEach

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on