Skip to content

Commit 98c78ee

Browse files
committed
Initial exploration of Promise handling in ClientSide Callbacks
1 parent f6abdfb commit 98c78ee

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

dash/dash-renderer/src/actions/callbacks.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const getVals = (input: any) =>
200200
const zipIfArray = (a: any, b: any) =>
201201
Array.isArray(a) ? zip(a, b) : [[a, b]];
202202

203-
function handleClientside(
203+
async function handleClientside(
204204
dispatch: any,
205205
clientside_function: any,
206206
config: any,
@@ -246,14 +246,10 @@ function handleClientside(
246246
dc.callback_context.states_list = state;
247247
dc.callback_context.states = stateDict;
248248

249-
const returnValue = dc[namespace][function_name](...args);
249+
let returnValue = dc[namespace][function_name](...args);
250250

251251
if (typeof returnValue?.then === 'function') {
252-
throw new Error(
253-
'The clientside function returned a Promise. ' +
254-
'Promises are not supported in Dash clientside ' +
255-
'right now, but may be in the future.'
256-
);
252+
returnValue = await returnValue;
257253
}
258254

259255
zipIfArray(outputs, returnValue).forEach(([outi, reti]) => {
@@ -504,15 +500,13 @@ export function executeCallback(
504500

505501
if (clientside_function) {
506502
try {
507-
return {
508-
data: handleClientside(
509-
dispatch,
510-
clientside_function,
511-
config,
512-
payload
513-
),
503+
const data = await handleClientside(
504+
dispatch,
505+
clientside_function,
506+
config,
514507
payload
515-
};
508+
);
509+
return {data, payload};
516510
} catch (error: any) {
517511
return {error, payload};
518512
}

0 commit comments

Comments
 (0)