Skip to content

Commit

Permalink
updated run method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 22, 2024
1 parent 0af3982 commit 8f217e2
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions packages/clients/walkerjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,28 +548,29 @@ export function Walkerjs(
return pushed;
}

function run(instance: WebClient.Instance) {
function run(instance: WebClient.Instance, state: WebClient.InitConfig = {}) {
const { config, destinations } = instance;
instance.config = assign(config, {});

// When run is called, the walker may start running
instance.allowed = true;

// Reset the run counter
instance.count = 0;

(instance.globals = assign(
// Load globals properties
// Use the default globals set by initialization
// Due to site performance only once every run
config.globalsStatic,
getGlobals(config.prefix),
)),
// Reset the queue for each run without merging
(instance.queue = []);
const newState = assign(
{
allowed: true, // When run is called, the walker may start running
count: 0, // Reset the run counter
queue: [], // Reset the queue for each run without merging
group: getId(), // Generate a new group id for each run
globals: assign(
// Load globals properties
// Use the static globals and search for tagged ones
// Due to site performance only once every run
config.globalsStatic,
getGlobals(config.prefix),
),
},
{ ...state },
);

// Generate a new group id for each run
instance.group = getId();
// Update the instance reference with the updated state
Object.assign(instance, newState);

// Reset all destination queues
Object.values(destinations).forEach((destination) => {
Expand Down

0 comments on commit 8f217e2

Please sign in to comment.