CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/done.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// This is a convenience function to provide as a callback when working interactively.
7
function _done(n, ...args): Function | void {
8
const start_time = Date.now();
9
const f = function (...args) {
10
if (n !== 1) {
11
try {
12
args = [JSON.stringify(args, null, n)];
13
} catch (error) {}
14
}
15
// do nothing
16
console.log(
17
`*** TOTALLY DONE! (${
18
(Date.now() - start_time) / 1000
19
}s since start) `,
20
...Array.from(args)
21
);
22
};
23
if (args.length > 0) {
24
f(...Array.from(args || []));
25
} else {
26
return f;
27
}
28
}
29
30
export function done(...args): Function | void {
31
return _done(0, ...Array.from(args));
32
}
33
export function done1(...args): Function | void {
34
return _done(1, ...Array.from(args));
35
}
36
export function done2(...args): Function | void {
37
return _done(2, ...Array.from(args));
38
}
39
40