Posts: 19
Joined: Wed May 03, 2017 11:13 pm

Async adapters

Tue Jun 27, 2017 1:22 am

Now that Syn.Bot has moved entirely into .NET Standard, could we get proper async/await support? Async adapter would be a good start.

What I mean - currently we can make synchronous adapters and event adapters, as stated in official documentation. Sync adapters are great because they're easy to implement and use within SIML. Event adapters, while asynchronous, are very verbose and require from SIML extra code to handle them, like shown here.

It'd be excellent if there was a way to implement async/await adapter - this way runtime would make use of asynchronous processing while not complicating SIML code that requires from programmer to know which adapter has event-based pattern and needs to be handled in special way.

Basically I'm thinking of AsyncAdapter class that would work exactly the same as current Adapter class, but would have EvaluateAsync method to override instead of Evaluate one, that would return Task<string> instead of string, making it possible for Syn.Bot to await evaluation in async manner. Likewise, SimlBot.Chat() method could make use of extra SimlBot.ChatAsync() that would return Task<ChatResult> instead of ChatResult, making it possible for us to await execution in async manner, exactly the same as Syn.Bot would await async adapter.

The general reason why I suggest those features is because C# offers excellent async/await approach that simplifies a lot of async patterns, instead of approaches available right now based on executing functions and getting results in callbacks, like it was done in .NET 4.0 times.

Thank you a lot for considering my idea.

User avatar
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Async adapters

Tue Jun 27, 2017 6:37 pm

A great suggestion indeed.

However, I will pen down my thoughts on this to help the team members take the necessary steps in case they plan to get this feature incorporated.

The <Event> element in SIML specification existed long before Syn Virtual Assistant (SVA) Prototype 8.5 was released. It was mainly added to assist event driven applications. Granted the verbosity, we did find it extremely useful in multi-threaded responses and event handling in SVA.

In SimlBot, all adapters are stored within the AdapterCollection class that implements ICollection<IAdapter>. Adding a new AsyncAdapter support would mean that the current interface would have to be split for both synchronous and asynchronous adapters. Both of which would share a common base interface say IBaseAdapter. Which would then change the AdapterCollection to ICollection<IBaseAdapter>. So we've got a breaking change there. The interpreter would have to type check the adapters before calling their respective Evaluate and EvaluateAsync methods. There's a small (negligible) overhead to type checking in .NET. In addition to that the interpreter would also need to raise warning logs in case an async adapter is approached via a synchronous Chat() method. To avoid type checks maybe we could have separate collections for the 2 adapter types.

If IAsyncAdapter is implemented then it would be imperative that a ChatAsync() method is also implemented. Otherwise it wouldn't make any sense.

Having pointed all that, I am certain that this is a great suggestion. Though a major undertaking I would love to see this being supported. Both SimlBot and OscovaBot are going to receive a lot of updates in the coming weeks. Hopefully we'll see this implemented.

Note: SIML is coming to OSCOVA. I will be making an announcement regarding a new flavor of SIML as part of our integration support.

Return to “Feature Request and Suggestions”

Who is online

Users browsing this forum: No registered users and 1 guest