Usage
:warning: Depending on your environment, the code may require
regeneratorRuntime
to be defined, for instance by importing regenerator-runtime/runtime.
First, require the polyfill at the entry point of your application
await import('regenerator-runtime/runtime.js');
// or
import 'regenerator-runtime/runtime.js';
Then, import the library where needed
const tape = await import('@async-abstraction/tape');
// or
import * as tape from '@async-abstraction/tape';
Examples
More examples in the test files.
Import
import tape from '@async-abstraction/tape' ;
fromString
import {
fromString,
fromArray,
fromCallable,
fromIterable,
fromAsyncIterable,
fromIterator,
fromReadStream,
} from '@async-abstraction/tape' ;
const tape = fromString( 'abracadabra' ) ;
// // OR
// const tape = fromArray( ... ) ;
// const tape = fromCallable( ... ) ;
// const tape = fromIterable( ... ) ;
// const tape = fromAsyncIterable( ... ) ;
// const tape = fromIterator( ... ) ;
// const tape = fromReadStream( ... ) ;
read
and unread
tape.read()
.then( character => console.log(character) ) // 'a'
.then( () => tape.read() )
.then( character => console.log(character) ) // 'b'
.then( () => tape.unread('Z') )
.then( () => tape.unread('X') )
.then( () => tape.read() )
.then( character => console.log(character) ) // 'X'
.then( () => tape.read() )
.then( character => console.log(character) ) // 'Z'
.then( () => tape.read() )
.then( character => console.log(character) ) // 'r'
// ...