Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to make datapipe wait for async functions that dynamically set experiment_id? #100

Open
xallysie opened this issue Jul 16, 2024 · 1 comment

Comments

@xallysie
Copy link

People usually have a predetermined experiment_id for each script/experiment.

Instead, I'm using a script that dynamically chooses from an array of experiment_ids, and then saves the data to one of these osf components. To choose which experiment_id to use, I need to first run an async function that reads data from an existing firebase database.

Unfortunately, I can't find a way to make this resolve before datapipe runs. I've tried pushing the async function to a separate node first, or adding an "on_start: async function()" property to the datapipe save_data node, but I keep getting the same error that the experiment_id is missing.

Here's an example of something I've tried:

const save_data_osf = {
    on_start: async function(){
        // wait for recruitment wave to be set
        osf_DataComponent_Name = await setRecruitmentWave();
    },
    type: jsPsychPipe,
    action: "save",
    experiment_id: osf_DataComponent_Name,
    filename: filename,
    data_string: ()=>jsPsych.data.get().csv()
};

If datapipe or jsPsych generally doesn't play well with async functions, I'll try something else, but putting this question here if there's an obvious solution!

@jodeleeuw
Copy link
Member

Hi @xallysie,

You can use the call-function plugin which supports asynchronous function calls. I'd add it to the timeline right before the save_data_osf trial, and store the ID in a global variable.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants