Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

parallel()() #37

Open
mrWh1te opened this issue Aug 2, 2020 · 4 comments
Open

parallel()() #37

mrWh1te opened this issue Aug 2, 2020 · 4 comments
Labels
botaction proposal New feature or change

Comments

@mrWh1te
Copy link
Owner

mrWh1te commented Aug 2, 2020

Basically Promise.all(actions), but.... before this, if running in a Pipe, then return the resolved value of Promise.all(), an array of Pipe values whose indexes correspond with the index in the actions de-spreaded array. Otherwise, if it's not running in a Pipe, then simply await the Promise.all() without returning any values.

concept

const parallel = (...actions: BotAction[]):BotAction => async(page, ...injects) => {
   // basically you want to reduce the functions to the Promises returned by the BotAction's
   const actionsPromises = actions.map(action is a Promise ? action : action is a Function ? action(page, ...injects) : action)
   if ( injects are piped ) 
      // then run the actions in parallel, return if pipe, otherwise dont bother
      then return await Promise.all(actionsPromises)
   else
     await Promise.all(actionsPromises)
}
@mrWh1te
Copy link
Owner Author

mrWh1te commented Aug 2, 2020

maybe?

const isPromise(obj: any): obj is Promise => obj && typeof obj.then == 'function'

@mrWh1te
Copy link
Owner Author

mrWh1te commented Aug 2, 2020

A useful use-case is like in Navigation, when you're changing a page through some page event but you need to wait for navigation to complete too before going to the next action, those BotAction's can be ran in parallel

@mrWh1te
Copy link
Owner Author

mrWh1te commented Aug 7, 2020

How would this work with #39 state()() ? Make it immutable/observable?

@mrWh1te mrWh1te changed the title Proposition: parallel() BotAction Proposition: parallel()() BotAction Aug 15, 2020
@mrWh1te mrWh1te added the proposal New feature or change label Aug 18, 2020
@mrWh1te mrWh1te changed the title Proposition: parallel()() BotAction parallel()() Aug 18, 2020
@mrWh1te
Copy link
Owner Author

mrWh1te commented Sep 5, 2020

What if parallel()() could create other pages from the same window, without using incognito, to do tasks in parallel pages with the same session?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
botaction proposal New feature or change
Projects
None yet
Development

No branches or pull requests

1 participant