D3.js queue.abort() Function

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Example 2: No function will be executed.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.