## What’s takeaway of this session
- The basic use of Promise and Fiber
- The combination of Promise and Fiber performs like Async/Await syntax
- The naive Async/Await syntax sadly does NOT work efficiently in Graphql-ruby
3. What’s takeaway of this session
1. The basic use of Promise and Fiber
2. ★ The combination of Promise and Fiber performs like Async/Await syntax
3. ★★ The naive Async/Await syntax sadly does NOT work efficiently in
★: hard for @sat0yu to explain
4. GraphQL as an integrator
*Note: just a part of the whole Quipper services
8. How to use Graphql-batch
- Build a loader so as inherit GraphQL::Batch::Loader
- which need implementing perform(...)fetching data in bulk
- Generate field values through the loader
X.rb Y.rb
ref. https://github.com/Shopify/graphql-batch
11. - A representation of an eventual value
- The value won’t be calculated until evaluating it (lazy-evaluation)
- Chain-able with other promises through .then(...)
What is “Promise”?
fulfill
rejectpending
fulfilled
rejected
※ .load(...) returns a promise
13. Async/Await in JavaScript
- Declared in ES2017(ES8); Almost all browsers have compatibility
- Convenient to write async processing with a synchronized-ish syntax
JavaScript
14. Pause and Resume for promises
- Declared in ES2017(ES8); Almost all browsers have compatibility
- Convenient to write async processing with a synchronized-ish syntax
sleeping...
Pause
Resume
JavaScript
63. What’s wrong with the naive Async/Await?
The naive Async/Await impl. returns
a value, not a promise as a result
Graphql-batch allows fields to
return a promise in place of a value
64. Is it possible to fix it?
- It makes me feel it’s do-able…
but it does not work even if modifying it as returning a promise
- The main difficulty comes from the difference in the promise life-cycle
between Graphql-batch and the handcrafted Async/Await implementation
65. Summary
- Explained the basic usage of Promise and Fiber
- Confirmed the combination of Promise and Fiber works as Async/Await syntax
- Observed that the naive impl. is not enough to work along with Graphql-batch
- Code available: https://github.com/sat0yu/heisei-ruby-kaigi01
Thank you for your time and attention 🙇