Open In App

D3.js queue.abort() Function

Last Updated : 04 Aug, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The queue.abort() function in d3.js is used to abort every function of deferred tasks. If any deferred task does not return any abort than it will continue to execute further.

Syntax:

queue.abort();

Parameters: This function does not accept any parameter.

Returns: It returns the object.

Below given are a few examples of the above function.

Example 1: Certain function calls will be executed.

HTML




<!DOCTYPE html> 
<html lang="en"
<head
    <meta charset="UTF-8"
    <meta name="viewport"
            path1tent="width=device-width, 
                       initial-scale=1.0"> 
    <title>Document</title
</head
<style
</style
<body
  <script src
  </script
  <script>
    function func1(){
      console.log("from function func1")
    }
    function func2(){
      console.log("from function func2")
    }
    function func3(){
      console.log("from function func3")
    }
    function func4(){
      setTimeout(func3, 500);
    }
    let q=d3.queue(3)
    q.defer(func1)
    q.defer(func4)
    q.abort()
    // This will not be executed.
    q.defer(func2)
    console.log(q)
    console.log("Size of q is: ",q._size)
  </script
</body
</html>


Output:

Example 2: No function will be executed.

HTML




<!DOCTYPE html> 
<html lang="en"
<head
    <meta charset="UTF-8"
    <meta name="viewport"
            path1tent="width=device-width, 
                       initial-scale=1.0"> 
    <title>Document</title
</head
<style
</style
<body
  <script src
  </script
  <script>
    function func1(){
      console.log("from function func1")
    }
    function func2(){
      console.log("from function func2")
    }
    function func3(){
      console.log("from function func3")
    }
    function func4(){
      setTimeout(func3, 500);
    }
    let q=d3.queue(3)
    // Using abort function to force
    // every deferred function to return abort.
    q.abort()
    // These functions will not be executed.
    q.defer(func1)
    q.defer(func4)
    q.defer(func2)
    console.log("No function will be executed.")
    console.log("Size of q is: ",q._size)
  </script
</body
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads