Make it easy to wrap pre-existing cob-style async apis
authorMarc Celani <marccelani@fb.com>
Mon, 3 Mar 2014 19:36:05 +0000 (11:36 -0800)
committerDave Watson <davejwatson@fb.com>
Mon, 10 Mar 2014 20:50:19 +0000 (13:50 -0700)
commit44ecd1efe287e2a4c7ba4c6618dced8f4919c629
tree5d55cf31f9219bcf42a090dafa5e79b966f0fde0
parent649cb97d1514634985fa4af370ce30adb79dd032
Make it easy to wrap pre-existing cob-style async apis

Summary:
Tao neesd a way to wrap its c-style async apis with Later. Although my comments suggest that you can do this, it turns out I never got around to implementing it. Well, here is the implementation.

Basically, we supply the callback to the pre-existing api, and that callback will fulfill a promise that is used internally within Later. This is thread safe because the async call is not made until the starter is fired, and we can use the future immediately for chaining then() calls.

Test Plan: unit test

Reviewed By: hannesr@fb.com

FB internal diff: D1197721
folly/wangle/Later-inl.h
folly/wangle/Later.h
folly/wangle/test/LaterTest.cpp