Skip to content

Commit

Permalink
Merge pull request #9070 from Expensify/tgolen-onready
Browse files Browse the repository at this point in the history
Simplify growl is ready
  • Loading branch information
Chris Kosuke Tseng authored May 18, 2022
2 parents a5f5329 + dc27ac3 commit d84f9ce
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/libs/Growl.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import CONST from '../CONST';
import createOnReadyTask from './createOnReadyTask';

const growlRef = React.createRef();
const growlReadyTask = createOnReadyTask();
let resolveIsReadyPromise;
const isReadyPromise = new Promise((resolve) => {
resolveIsReadyPromise = resolve;
});

function setIsReady() {
growlReadyTask.setIsReady();
resolveIsReadyPromise();
}

/**
Expand All @@ -17,7 +19,7 @@ function setIsReady() {
* @param {Number} [duration]
*/
function show(bodyText, type, duration = CONST.GROWL.DURATION) {
growlReadyTask.isReady().then(() => growlRef.current.show(bodyText, type, duration));
isReadyPromise.then(() => growlRef.current.show(bodyText, type, duration));
}

/**
Expand Down

0 comments on commit d84f9ce

Please sign in to comment.