demos/02-speak-up.js
function speakIt({ action }) {
    const { toSpeak } = action.payload

    // Remember: unlike Promises, which share a similar construction,
    // the observable function is not run until the Observable recieves
    // a subscribe() call.
    return new Observable(observer => {
      try {
        const say = require("say")
        say.speak(toSpeak, null, null, () => {
          observer.complete()
        })

        // An Observable allows for cancellation by returning a
        // cancellation function
        return () => {
          say.stop()
        }
      } catch (error) {
        log("-- speech synthesis not available --")
        observer.error()
      }
    })
  }
function speakIt({ action }) {
    const { toSpeak } = action.payload

    // Remember: unlike Promises, which share a similar construction,
    // the observable function is not run until the Observable recieves
    // a subscribe() call.
    return new Observable(observer => {
      try {
        const say = require("say")
        say.speak(toSpeak, null, null, () => {
          observer.complete()
        })

        // An Observable allows for cancellation by returning a
        // cancellation function
        return () => {
          say.stop()
        }
      } catch (error) {
        log("-- speech synthesis not available --")
        observer.error()
      }
    })
  }
function speakIt ( { action } ) { const { toSpeak } = action . payload // Remember: unlike Promises, which share a similar construction, // the observable function is not run until the Observable recieves // a subscribe() call. return new Observable ( observer => { try { const say = require ( "say" ) say . speak ( toSpeak , null , null , ( ) => { observer . complete ( ) } ) // An Observable allows for cancellation by returning a // cancellation function return ( ) => { say . stop ( ) } } catch ( error ) { log ( "-- speech synthesis not available --" ) observer . error ( ) } } ) }
Return an observable that begins when subscribe is called, and completes when say.speak ends
Return an observable that begins when subscribe is called and completes when say . speak ends