import React from "react" ; /**
 * Problems:
 * 1. Wer currently don't use the result or error from the Promise
 * 2. We would need to write this every time
 *
 * Goal: Abstract status and loading
 *
 * NOTE: This might change!
 */ export function wrapPromise ( promise ) { let status = "pending" ; let result ; let suspender = promise . then ( ( r ) => { status = "success" ; result = r ; } , ( e ) => { status = "error" ; result = e ; } ) ; return { read ( ) { if ( status === "pending" ) { throw suspender ; } else if ( status === "error" ) { throw result ; } else if ( status === "success" ) { return result ; } } , } ; } const waitPromise = new Promise ( ( resolve , reject ) => { setTimeout ( ( ) => { resolve ( "Yay" ) ; } , 2000 ) ; } ) ; const resource = wrapPromise ( waitPromise ) ; const WaitForMeTwoSecResource = ( ) => { return < div > { resource . read ( ) } < /div>; } ; export default WaitForMeTwoSecResource ;