Using Async api

101 views
Skip to first unread message

Jeremy Holt

unread,
Sep 30, 2014, 2:28:09 PM9/30/14
to rav...@googlegroups.com
I'm starting a new project and decided I would try to use the async api, instead of the sync api which I am comfortable with.

I've clearly misunderstood something here.

The tests for the code below works fine.

However, running the code from the webapi app the code hangs at await session.StoreAsync(farmArea).

(I've stuck the new DocumentStore() into the method for testing purposes only).

The docStore is picking up correctly the connection string from web.config.

Is there some additional configuration required to use the async api?

public async Task<FarmAreaSaveModel> Save(FarmAreaSaveModel model)
        {
            using (var docStore = new DocumentStore())
            {
                docStore.ConnectionStringName = "RavenHQ";
                docStore.Conventions = new DocumentConvention {IdentityPartsSeparator = "-"};
                docStore.Initialize();
 
                using (var session = docStore.OpenAsyncSession())
                {
                    var farmArea = model.Id.IsNullOrEmpty()
                        ? new FarmArea()
                        : await session.LoadAsync<FarmArea>(model.Id) ?? new FarmArea();
 
                    farmArea.Name = model.Name;
 
                    await session.StoreAsync(farmArea);
                    model.Id = farmArea.Id;
                    model.Success = true;
                    model.Message = "Saved farm area";
 
                    await session.SaveChangesAsync();
 
                    return model;
                }
            }
        }

This code works as expected

public FarmAreaSaveModel Save(FarmAreaSaveModel model)
        {
            using (var docStore = new DocumentStore())
            {
                docStore.ConnectionStringName = "RavenHQ";
                docStore.Conventions = new DocumentConvention { IdentityPartsSeparator = "-" };
                docStore.Initialize();
 
                using (var session = docStore.OpenSession())
                {
                    var farmArea = model.Id.IsNullOrEmpty()
                        ? new FarmArea()
                        : session.Load<FarmArea>(model.Id) ?? new FarmArea();
 
                    farmArea.Name = model.Name;
 
                    session.Store(farmArea);
                    model.Id = farmArea.Id;
                    model.Success = true;
                    model.Message = "Saved farm area";
 
                    session.SaveChanges();
 
                    return model;
                }
            }
        }

Chris Marisic

unread,
Sep 30, 2014, 2:59:09 PM9/30/14
to rav...@googlegroups.com
When it's hanging are you selfhosting webapi, are you hosting inside ASP.NET+IIS, are you doing new MyService().Foo() from inside a unit test?

Jeremy Holt

unread,
Sep 30, 2014, 4:05:16 PM9/30/14
to rav...@googlegroups.com
I'm hosting inside ASP.NET + IIS Express (default in VS 2013)

Oren Eini (Ayende Rahien)

unread,
Sep 30, 2014, 10:13:41 PM9/30/14
to ravendb
Can you send us a repro? A project that shows this issue?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeremy Holt

unread,
Oct 2, 2014, 9:18:35 AM10/2/14
to rav...@googlegroups.com
Sorry for the delay - no internet for the last couple of days.


Thanks
Jeremy

Oren Eini (Ayende Rahien)

unread,
Oct 2, 2014, 2:01:21 PM10/2/14
to ravendb

Jeremy Holt

unread,
Oct 2, 2014, 2:59:15 PM10/2/14
to rav...@googlegroups.com
Oren,

Thanks for creating the issue, but surely it can't be a bug in Raven - if this were a common problem it would have been picked up ages ago?

Is there some configuration that I missed in webconfig?

Thanks
Jeremy

Chris Marisic

unread,
Oct 2, 2014, 3:09:52 PM10/2/14
to rav...@googlegroups.com
I think he just opened an issue for him to not lose track of this post

Oren Eini (Ayende Rahien)

unread,
Oct 2, 2014, 3:31:35 PM10/2/14
to ravendb
this is just so we can assign it easily to one of our people.

Jeremy Holt

unread,
Oct 2, 2014, 3:48:53 PM10/2/14
to rav...@googlegroups.com
Ah. understood.
Thanks

Jeremy Holt

unread,
Oct 3, 2014, 3:05:42 PM10/3/14
to rav...@googlegroups.com
Pawel, Oren

Thanks so much for your help. Thanks to the links I now have a much better understanding of how the async api works.

Jeremy
Reply all
Reply to author
Forward
0 new messages