All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
If the fasting is an obligation, such as fasting in Ramadan or making up for a day missed in Ramadan, then it is not permissible to interrupt it after starting it for the reason that you mentioned, but if you are fasting a voluntary fast, then it is permissible for you to break the fast, and you are not sinful in this case and are not required to make it up.
Ibn Qudaamah said in Al-Mughni:
“In brief, if one has started a voluntary fast, it is desirable for him to complete it, but he is not obliged to do so, and if he interrupts his fasting, then he is not required to make up for it. It was reported from Ibn 'Umar and Ibn ‘Abbaas that they woke up in the morning while fasting and then broke their fast. Ibn 'Umar said, 'It is acceptable, unless it is a vow or making up for Ramadan.' Ibn ‘Abbaas said, 'If a man fasts voluntarily and then he wishes to break his fast, then he may do so. Also, if one starts a voluntary prayer and then wishes to abandon it, he may do so.' Ibn Mas’ood said, 'If you wake up in the morning while willing to fast, then you have the choice, you may fast if you wish, and you may break the fast if you wish.' This is the view of Ahmad, Ath-Thawri, Ash-Shaafi'i, and Is-haaq.”
If the function that you mentioned involves some evil matters, such as music, then you have to advise the person who caused this evil; if advice is of no avail, then it is not permissible for you to stay in this function unless you need to stay in it; in which case you should deny the evil in your heart, and you will not be sinful then.
Ibn Taymiyyah said:
“If a man listens to disbelief, lies, backbiting, singing and flute (a musical instrument) unintentionally, and he was accidentally passing by a road and he heard that, then, by the agreement of all the Muslims [Muslim scholars], he is not sinful. But if he sits and listens to it and does not deny it either with his heart, his tongue, or his hand, then, by the agreement of all the Muslims, he is sinful, as Allah says (what means) {And when you see those who engage in [offensive] discourse concerning Our verses, then turn away from them until they enter into another conversation. And if Satan should cause you to forget, then do not remain after the reminder with the wrongdoing people. And those who fear Allah are not held accountable for the disbelievers at all, but [only for] a reminder - that perhaps they will fear Him.} [Quran 6:68-69] Allah also says (what means): {And it has already come down to you in the Book that when you hear the verses of Allah [recited], they are denied [by them] and ridiculed; so do not sit with them until they enter into another conversation. Indeed, you would then be like them.} [Quran 4:140] So Allah considered the one who sits with them and listens to them without denying it like the doer. It is for this reason that it is said, 'The listener is an associate of the backbiter.' It was also reported that 'if someone witnesses a sin and hates it, then he is like the one who was absent from it, and he who is absent from it but approves it, he is like the one who witnessed it.' If he witnesses it for a need or because he was compelled, then he should deny it with his heart, because the Prophet said, 'Whoever amongst you sees an evil should change it with his hand (i.e. physically), and if he is unable to do this, then he should change it with his tongue (i.e. verbally), and if he is unable to do this, then he should change it with his heart (by detesting it in his heart), and that is the weakest level of faith.”
Allah knows best.