Skip to content

async_extensions

j-show edited this page Mar 1, 2019 · 2 revisions

Extend asynchronous functions to define generic asynchronous code encoding specifications

TCallback

  • Note
    • Consolidate the list of callback functions in the form of arrays
    • Centralized control trigger form
    • Inherited from TSeal
  • Class Function
    • create(opt, limit, callback)
      • Note
        • Class object Initialization
      • Parameters
        • [opt] Core parameters
          • opt.memory=false Whether to remember the last trigger state
          • opt.fire=false Whether to trigger automatically
          • opt.once=true Whether to call a callback only once
          • opt.unique=false Whether to allow function repetition
        • limit Upper limit of callback function
        • callback callback function after all callbacks are triggered
      • Return
        • object
  • Object Function
    • lock()
      • Note
        • Lock object, no trigger callback is allowed after locking
      • Return
        • Return boolean
    • unlock()
      • Note
        • Unlock
      • Return
        • Return boolean
    • on([func...])
      • Note
        • Add callback function
      • Parameters
        • func callback function
          • Allow array of callback functions
      • Return
        • this
    • off(func)
      • Note
        • Delete callback function
      • Parameters
        • func Deletes the specified callback function
      • Return
        • this
    • fire()
      • Note
        • Trigger callback function
      • Parameters
        • Parameters will be brought into all callback functions
      • Return
        • this
    • fireWith(own, [args], [done])
      • Note
        • Trigger the callback function with the parameter own as this
      • Parameters
        • own this replaces the object
        • args Parameters that trigger callbacks
        • done When all callbacks are complete, the trigger function
      • Return
        • this
    • unique()
      • Note
        • Delete duplicate callback function, invalid when locking state
      • Return
        • this
    • has(func)
      • Note
        • Determine if the callback function repeats
      • Return
        • this
  • Property
    • length
      • Note
        • Number of callback functions
      • Readonly
      • Return
        • number
    • locked
      • Note
        • Whether the state is locked
      • Read & Write
      • Return
        • boolean

TDeferred

  • Note
    • Asyn extension class, observer mode
    • Asynchronous processing based on TCallback class in a manner consistent with jQuery's deferred
    • Inherited from TSeal
  • Class Function
    • create(limit, callback)
      • Note
        • Class object Initialization
      • Parameters
        • limit Upper limit of callback function
        • callback callback function after all callbacks are triggered
      • Return
        • object
  • Object Function
    • promise([own], [max])
      • Note
        • Return Promise object
        • By setting max, you can use the notify function to trigger progress events
        • Deferred object must use the return object of the Promise function for the function to trigger the event
      • Parameters
        • own this object of the callback function
        • max Maximum number of triggers for progress events
      • Return
        • this
    • done(func)
      • Note
        • Binding Success Event callback function, allowing multiple bindings
        • Triggered by the resolve function
      • Parameters
        • func callback function
      • Return
        • this
    • fail(func)
      • Note
        • Binding failed event callback function that allows multiple bindings
        • Triggered by the reject function
      • Parameters
        • func callback function
      • Return
        • this
    • always(func)
      • Note
        • Binding completes event callback function, allowing multiple bindings
        • Triggered after done, fail events
      • Parameters
        • func callback function
      • Return
        • this
    • warn(func)
      • Note
        • Binding Warning Event callback function, allowing multiple bindings
        • Warning event allows multiple triggers
        • triggered by the alarm function
      • Parameters
        • func callback function
      • Return
        • this
    • progress(func)
      • Note
        • Binding Progress event callback function, allowing multiple bindings
        • Progress events allow multiple triggers
        • triggered by the notify function,Automatically triggers the `done' function when the number of triggers reaches the upper limit
      • Parameters
        • func callback function
      • Return
        • this
    • resolve(arg)
      • Note
        • Trigger done event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • reject(arg)
      • Note
        • Trigger fail event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • alarm(arg)
      • Note
        • Trigger warn event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • notify(arg)
      • Note
        • Trigger progress event
      • Parameters
        • arg Passing parameters
      • Return
        • this
  • Property
    • state
      • Note
        • Current asynchronous state
      • Readonly
      • Return
        • number

TPromise

  • Note
    • Extending asynchronous chained objects
    • Function Extensions for Promise
  • Class Function
    • create([callback], [simple=false])
      • Note
        • Class object Initialization
      • Parameters
        • callback callback function after all callbacks are triggered
        • simple Whether it's a simple mode
          • simple=true,warnprogress Event takes effect
          • simple=false,warnprogress Invalid event
      • Return
        • object
  • Object Function
    • promise([max])
      • Note
        • Return Promise object
        • By setting max, you can use the notify function to trigger progress events
      • Parameters
        • max Maximum number of triggers for progress events
      • Return
        • Promise object
    • done(func)
      • Note
        • Binding Success Event callback function, allowing multiple bindings
        • Triggered by the resolve function
      • Parameters
        • func callback function
      • Return
        • this
    • fail(func)
      • Note
        • Binding failed event callback function that allows multiple bindings
        • Triggered by the reject function
      • Parameters
        • func callback function
      • Return
        • this
    • always(func)
      • Note
        • Binding completes event callback function, allowing multiple bindings
        • Triggered after donefail event
      • Parameters
        • func callback function
      • Return
        • this
    • warn(func)
      • Note
        • Binding Warning Event callback function, allowing multiple bindings
        • Warning event allows multiple triggers
        • triggered by the alarm function
      • Parameters
        • func callback function
      • Return
        • this
    • progress(func)
      • Note
        • Binding Progress event callback function, allowing multiple bindings
        • Progress events allow multiple triggers
        • triggered by the notify function,Automatically triggers the `done' function when the number of triggers reaches the upper limit
      • Parameters
        • func callback function
      • Return
        • this
    • resolve(arg)
      • Note
        • Trigger done event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • reject(arg)
      • Note
        • Trigger fail event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • alarm(arg)
      • Note
        • Trigger warn event
      • Parameters
        • arg Passing parameters
      • Return
        • this
    • notify(arg)
      • Note
        • Trigger progress event
      • Parameters
        • arg Passing parameters
      • Return
        • this

Callback([flag=once memory limit], [limit=50], [callback])

  • Note
    • Get callback management objects through functions, centralize management callback lists, and uniformly trigger
  • Parameters
    • flag=once memory limit Callback Object label
      • Label definition, same as TCallback class
    • limit=50 Callback List Upper Limit
    • callback When the callback list trigger is complete, the triggered function
  • Return
    • Return TCallback object

Deferred([simple=false], [callback])

  • Note
    • Asynchronous Operation objects
    • Suitable for different asynchronous modes based on simple parameters
  • Parameters
    • simple Asynchronous mode
      • simple=true,Simple mode, based on TPromise class, can be adapted to async/awit asynchronous operation
      • simple=false,Complex mode, based on TDeferred class, can be adapted to all environments
      • simple is number,Complex mode, based on TDeferred class, Simple is the upper limit of the callback function
    • callback End callback, triggered after always event is complete
  • Return
    • Return TDeferred/TPromise object

Promise([callback])

  • Note
    • Promise Extended Objects
    • Based on TPromise
  • Parameters
    • callback callback function after all callbacks are triggered
  • Return
    • Return TPromise object

Async(gen, [data], [owner])

  • Note
    • Generator function converted to Promise object
  • Parameters
    • gen Generator function
    • data Successful trigger parameters
    • owner Replace this object
  • Return
    • Return Promise object

Done(func)

  • Note
    • normal function converted to async function
    • Trigger done event
  • Parameters
    • func normal function
  • Return
    • Return TPromise object