Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 5 | package lib |
| 6 | |
Todd Wang | f6a0688 | 2015-02-27 17:38:01 -0800 | [diff] [blame] | 7 | import "time" |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 8 | |
Todd Wang | f6a0688 | 2015-02-27 17:38:01 -0800 | [diff] [blame] | 9 | // Javascript uses millisecond time units. This is both because they are the |
| 10 | // native time unit, and because otherwise JS numbers would not be capable of |
| 11 | // representing the full time range available to Go programs. |
| 12 | // |
| 13 | // TODO(bjornick,toddw): Pick a better sentry for no timeout, or change to using |
| 14 | // VDL time.WireDeadline. |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 15 | const JSRPCNoTimeout = int64(6307200000000) // 200 years in milliseconds |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 16 | |
| 17 | func GoToJSDuration(d time.Duration) int64 { |
Todd Wang | f6a0688 | 2015-02-27 17:38:01 -0800 | [diff] [blame] | 18 | return int64(d / time.Millisecond) |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | func JSToGoDuration(d int64) time.Duration { |
Todd Wang | f6a0688 | 2015-02-27 17:38:01 -0800 | [diff] [blame] | 22 | return time.Duration(d) * time.Millisecond |
Matt Rosencrantz | 4aabe57 | 2014-10-22 09:25:50 -0700 | [diff] [blame] | 23 | } |