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

Start/pause/restart buttons in notebook #15

Open
qti3e opened this issue May 8, 2018 · 3 comments
Open

Start/pause/restart buttons in notebook #15

qti3e opened this issue May 8, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@qti3e
Copy link
Collaborator

qti3e commented May 8, 2018

No description provided.

@piscisaureus
Copy link
Member

Good idea -- do you have any implementation ideas?

@qti3e
Copy link
Collaborator Author

qti3e commented May 12, 2018

restart is easy to implement, we just need to replace the Iframe, but I'm not sure about my idea about pause/resume in browsers...

console.log("Hello world")
console.log("next line")

to:

let stopped = false;
let pending;
function stop() {
  stopped = true;
}
function resume() {
  stopped = false;
  pending.f();
  pending.promise.resolve();
}

function run(f) {
  const promise = createResolvable();
  if (stopped) {
    pending = { promise, f };
  } else {
    f();
    promise.resolve();
  }
  return promise;
}

(async () => {
  await run(() => console.log("Hello world");
  await run(() => console.log("next line"));
}) ();

Also we can do:

function run(code) {
  let pending;
  let paused = false;
  setTimeout(async () => {
    for (const f of code) {
      pending = createResolvable();
      if (!paused) pending.resolve();
      await pending();
      f();
    }
  });
  return {
    pause() {
      if (paused) return;
      paused = true;
    },
    resume() {
      paused = false;
      if (pending instanceof Promise) {
        pending.resolve();
      }
    }
  }
}
const c = run( [
() => console.log("Hello world"),
() => console.log("next line")
]);
// c.pause()
// c.resume()

@qti3e
Copy link
Collaborator Author

qti3e commented May 13, 2018

Forget about that : )
We can do it very simple for now, maybe we can pause/resume at cell level.

@qti3e qti3e added the enhancement New feature or request label May 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants