class_docstr: A collection of callbacks added to a Tornado IOLoop that can be removed
  as a group.
class_docstr_tok: ["A","collection","of","callbacks","added","to","a","Tornado","IOLoop","that","can","be","removed","as","a","group","."]
docstr: Adds a callback to be run on the nex
  
  The passed-in ID can be used with remove_next_tick_callback.
docstr_tok: ["Adds","a","callback","to","be","run","on","the","nex","The","passed-in","ID","can","be","used","with","remove_next_tick_callback","."]
code: def add_next_tick_callback(
      self, callback: Callback, callback_id: ID
  ) -> ID:
      """Adds a callback to be run on the nex
  
      The passed-in ID can be used with remove_next_tick_callback.
  
      """
  
      def wrapper() -> None | Awaitable[None]:
          # this 'removed' flag is a hack because Tornado has no way to remove
          # a "next tick" callback added with IOLoop.add_callback. So instead
          # we make our wrapper skip invoking the callback.
          #
          # also: mypy cannot handle attrs on callables: https://github.com/python/mypy/issues/2087
          if wrapper.removed:  # type: ignore
              return None
          self.remove_next_tick_callback(callback_id)
          return callback()
  
      wrapper.removed = False  # type: ignore
  
      def remover() -> None:
          wrapper.removed = True  # type: ignore
  
      self._assign_remover(
          callback,
          callback_id,
          self._next_tick_callback_removers,
          remover,
      )
      self._loop.add_callback(wrapper)
      return callback_id
  
imports: from __future__ import annotations
  import logging
  import sys
  import threading
  from collections import defaultdict
  from traceback import format_exception
  from typing import TYPE_CHECKING, Any, Awaitable, Callable, Union
  import tornado
  from tornado import gen
  from ..core.types import ID
label_desc: Use image node_id 6 for calling the _CallbackGroup obj's underlying member method code with example usage: obj.add_next_tick_callback(callback, callback_id) and returns: callback_id, callback, None