Promises

Tags
 
 
@ReactMethod fun createCalendarEvent(name: String, location: String, promise: Promise) { try { val eventId = ... promise.resolve(eventId) } catch (e: Throwable) { promise.reject("Create Event Error", e) } }
마지막 인자Promise로 지정하면 이 메소드는 promise를 반환하는 메소드가 된다.
즉 위의 메소드를 해석해보면 다음과 같다.
type CreateCalendarEvent = (name: String, location: String): Promise<any>
const onSubmit = async () => { try { const eventId = await CalendarModule.createCalendarEvent( 'Party', 'My House', ); console.log(`Created a new event with id ${eventId}`); } catch (e) { console.error(e); } };