Interface IAsyncTask<TEvent, TMobile>

Since

3.1.0 AsyncTask enables proper and easy use of concurrency to improve speed and performance.

Example

import AsyncTask from '@smartface/native/asynctask';
var asynctask = new AsyncTask();
asynctask.task = function () {
// do something
};
asynctask.onComplete = function () {
console.log("AsyncTask is completed.");
};

asynctask.run();

Type Parameters

Hierarchy

Methods

  • Creates an event emitter instance to listen for the actions

    Returns

    Call the function to remove the event

    Parameters

    • eventName: "complete" | "cancelled" | "preExecute" | TEvent
    • callback: EventListenerCallback

      Gets as any arguments as it needs

    Returns (() => void)

      • (): void
      • Creates an event emitter instance to listen for the actions

        Returns

        Call the function to remove the event

        Returns void

  • Creates an event emitter instance to listen for the actions

    Returns

    Call the function to remove the event

    Parameters

    • eventName: "complete" | "cancelled" | "preExecute" | TEvent
    • callback: EventListenerCallback

      Gets as any arguments as it needs

    Returns (() => void)

      • (): void
      • Creates an event emitter instance to listen for the actions

        Returns

        Call the function to remove the event

        Returns void

  • Removes the specified event and invokes the callback after it is removed

    Parameters

    Returns void

  • Triggers the event manually.

    Parameters

    • event: "complete" | "cancelled" | "preExecute" | TEvent
    • Rest ...args: any[]

      Arguments that needs to be passed down

    Returns void

  • Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

    Parameters

    Returns void

  • Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

    Parameters

    Returns void

  • Runs the task.

    Method

    run

    Android

    Ios

    Since

    3.1.0

    Returns void

  • Attempts to cancel execution of this task. For Android, This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. For Android, If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

    Property

    Android

    Ios

    Since

    3.2.2

    Returns

    false For Android, if the task could not be cancelled, typically because it has already completed normally; true otherwise.

    Returns void

Properties

nativeObject: any
ios: TMobile["ios"]
android: TMobile["android"]
onPreExecute: (() => void)

Type declaration

    • (): void
    • Runs on the UI thread before onComplete.

      Method

      onPreExecute

      Deprecated

      Android

      Since

      3.2.2

      Example

      import AsyncTask from '@smartface/native/global/asynctask';

      const task = new AsyncTask();
      task.on(AsyncTask.Events.PreExecute, () => {
      console.info('onPreExecute');
      });

      Returns void

onCancelled: (() => void)

Type declaration

    • (): void
    • Runs on the UI thread after cancel() is invoked

      Method

      onCancelled

      Android

      Deprecated

      Ios

      Since

      3.2.2

      Example

      import AsyncTask from '@smartface/native/global/asynctask';

      const task = new AsyncTask();
      task.on(AsyncTask.Events.Cancelled, () => {
      console.info('onCancelled');
      });

      Returns void

Events

task: (() => void)

Type declaration

    • (): void
    • This event describes task of AsyncTask instance.

      task

      Android

      Ios

      Since

      3.1.0

      Returns void

onComplete: (() => void)

Type declaration

    • (): void
    • This event invokes when task is completed.

      onComplete

      Android

      Ios

      Deprecated

      Since

      3.1.0

      Example

      import AsyncTask from '@smartface/native/global/asynctask';

      const task = new AsyncTask();
      task.on(AsyncTask.Events.Complete, () => {
      console.info('onComplete');
      });

      Returns void

Generated using TypeDoc