def asyncRun(self, cb, *args, **kwargs):
        def _future_execute(f, cb, *args, **kwargs):
            try:
                # Only execute `cb` if the future wasn't cancelled
                if f.set_running_or_notify_cancel():
                    f.set_result(cb(*args, **kwargs))
            except Exception as e:
                f.set_exception(e)
            # return False so that glib will automatically remove the
            # idle source
            return False

        def _future_cancel(handle, f):
            if f.cancelled():
                glib.source_remove(handle)

        f = Future()
        handle = glib.idle_add(partial(_future_execute, f,
                                       cb, *args, **kwargs))
        f.add_done_callback(partial(_future_cancel, handle))
        return f
Helper call to run a callback `cb` within the task's main loop.
dataset/ETHPy150Open facebook/sparts/sparts/tasks/dbus.py/DBusTask.asyncRun