0.0.3 • Published 5 years ago

ready-promise v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

ready-promise NPM version

Wait for the resource initialization is complete.

Installation

$ npm install ready-promise --save

Usage

import readyPromise from 'ready-promise'

const isJsBridgeLoaded = () => window.jsBridge

readyPromise(isJsBridgeLoaded, {
  rate: 50,
  timeout: 1500
}).then(() => {
  console.log('jsBridge loaded')
}).catch(e => {
  console.log('jsBridge loaded error or timeout')
})

API

readyPromise(watchFunc, options)

  • watchFunc (Function)

    To determine whether a variable to be monitored exists or meets the conditions, you need to implement it yourself, returning true or false.

  • options

    • rate (Number) Unit ms, the frequency of executing watchFunc, default 50.
    • timeout (Number) Unit ms, judge the timeout maximum duration limit, the default 1500.