def async_request_method(d: ApiDefinition, is_subscription: bool):
    method_name = GeneratorUtils.request_method_name(d, is_subscription)
    original_sig = GeneratorUtils.signature(d.request_method)
    signature = GeneratorUtils.request_signature(d, is_subscription)
    param_values = [(p.name if (p.name != d.subscription_flag_name) else f'{(d.subscription_flag_value if is_subscription else (not d.subscription_flag_value))}') for p in original_sig.parameters.values()]
    if is_subscription:
        return f'''

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        {init_request_id(d, d.request_method)}
        ret: SubscriptionGenerator = None
        with self._lock:
            ret = {init_subscription(d)}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        return ret'''
    if ((d.callback_methods is not None) or (d.done_method is not None)):
        return f'''

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        loop = asyncio.get_running_loop()
        future = loop.create_future()
        def cb(res: {GeneratorUtils.request_return_type(d, is_subscription)}):
            loop.call_soon_threadsafe(future.set_result, res)
        {init_request_id(d, d.request_method)}
        with self._lock:
            {init_callback(d, d.request_method, 'cb')}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        res = (await future)
        if isinstance(res, IbError):
            raise res
        return res'''
    else:
        return f'''

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        {init_request_id(d, d.request_method)}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        return None'''
def async_request_method(d: ApiDefinition, is_subscription: bool):
    method_name = GeneratorUtils.request_method_name(d, is_subscription)
    original_sig = GeneratorUtils.signature(d.request_method)
    signature = GeneratorUtils.request_signature(d, is_subscription)
    param_values = [(p.name if (p.name != d.subscription_flag_name) else f'{(d.subscription_flag_value if is_subscription else (not d.subscription_flag_value))}') for p in original_sig.parameters.values()]
    if is_subscription:
        return f'

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        {init_request_id(d, d.request_method)}
        ret: SubscriptionGenerator = None
        with self._lock:
            ret = {init_subscription(d)}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        return ret'
    if ((d.callback_methods is not None) or (d.done_method is not None)):
        return f'

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        loop = asyncio.get_running_loop()
        future = loop.create_future()
        def cb(res: {GeneratorUtils.request_return_type(d, is_subscription)}):
            loop.call_soon_threadsafe(future.set_result, res)
        {init_request_id(d, d.request_method)}
        with self._lock:
            {init_callback(d, d.request_method, 'cb')}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        res = (await future)
        if isinstance(res, IbError):
            raise res
        return res'
    else:
        return f'

    async def {method_name}{signature}:
        {GeneratorUtils.doc_string(d.request_method)}
        {init_request_id(d, d.request_method)}
        self._writer.queue.put({bind_method(d, d.request_method, param_values)})
        return None'