def callback_method(d: ApiDefinition, m: Callable):
    if (d.subscription_flag_name is not None):
        return f'''

    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        is_subscription: bool = False
        with self._lock:
            is_subscription = {request_id(d, m)} in self._subscriptions
            {update_response(d, m)}
        if is_subscription:
            self.call_streaming_cb({request_id(d, m)}, {streaming_instance(d, m)})
            return
        {call_response_cb_if_done(d, m)}'''
    elif (not d.is_subscription):
        return f'''
    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        with self._lock:
            {update_response(d, m)}
        {call_response_cb_if_done(d, m)}'''
    else:
        return f'''

    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        self.call_streaming_cb({request_id(d, m)}, {streaming_instance(d, m)})'''
def callback_method(d: ApiDefinition, m: Callable):
    if (d.subscription_flag_name is not None):
        return f'

    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        is_subscription: bool = False
        with self._lock:
            is_subscription = {request_id(d, m)} in self._subscriptions
            {update_response(d, m)}
        if is_subscription:
            self.call_streaming_cb({request_id(d, m)}, {streaming_instance(d, m)})
            return
        {call_response_cb_if_done(d, m)}'
    elif (not d.is_subscription):
        return f'
    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        with self._lock:
            {update_response(d, m)}
        {call_response_cb_if_done(d, m)}'
    else:
        return f'

    def {GeneratorUtils.method_declaration(m)}:
        {GeneratorUtils.doc_string(m)}
        self.call_streaming_cb({request_id(d, m)}, {streaming_instance(d, m)})'