This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Provider: TimelineProvider { | |
private let quoteManager = QuoteManager() | |
[...] | |
func getSnapshot(in context: Context, completion: @escaping (QuoteEntry) -> ()) { | |
if context.isPreview { | |
let quote = Quote(quote: "Roses are red", author: "Nobody knows") | |
completion(QuoteEntry(date: Date(), quote: quote)) | |
} else { | |
let quote = quoteManager.getSingleQuote() | |
completion(QuoteEntry(date: Date(), quote: quote)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@main | |
struct DailyQuote_Complications: Widget { | |
let kind: String = "ro.bartis.DailyQuote.Complications" | |
var body: some WidgetConfiguration { | |
StaticConfiguration(kind: kind, provider: Provider()) { entry in | |
DailyQuote_ComplicationsEntryView(entry: entry) | |
} | |
.configurationDisplayName("Daily Quote") | |
.description("This is a complication that shows you a new quote evey day") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct DailyQuote_ComplicationsEntryView : View { | |
@Environment(\.widgetFamily) var widgetFamily | |
var entry: Provider.Entry | |
var body: some View { | |
switch widgetFamily { | |
case .accessoryCorner: | |
ComplicationCorner() | |
case .accessoryCircular: | |
ComplicationCircular() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ComplicationInline : View { | |
var body: some View { | |
Text("This will be a quote") | |
.widgetAccentable(true) | |
.unredacted() | |
} | |
} | |
struct ComplicationCircular : View { | |
var body: some View { | |
Text("This will be a quote") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Start(w io.Writer) error { | |
tracing.Lock() | |
defer tracing.Unlock() | |
if err := runtime.StartTrace(); err != nil { | |
return err | |
} | |
go func() { | |
for { | |
data := runtime.ReadTrace() | |
if data == nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Trace(w io.Writer) error { | |
if err := runtime.StartTrace(); err != nil { | |
return err | |
} | |
defer runtime.StopTrace() | |
go func() { | |
for { | |
data := runtime.ReadTrace() | |
if data == nil { | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (l *loggingT) setV(pc uintptr) Level { | |
fn := runtime.FuncForPC(pc) | |
file, _ := fn.FileLine(pc) | |
// The file is something like /a/b/c/d.go. We want just the d. | |
if strings.HasSuffix(file, ".go") { | |
file = file[:len(file)-3] | |
} | |
if slash := strings.LastIndex(file, "/"); slash >= 0 { | |
file = file[slash+1:] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
func main() { | |
for i := 0 ; i< 4; i++ { | |
test(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (h *boringHMAC) Reset() { | |
if h.needCleanup { | |
C._goboringcrypto_HMAC_CTX_cleanup(&h.ctx) | |
} else { | |
h.needCleanup = true | |
// Note: Because of the finalizer, any time h.ctx is passed to cgo, | |
// that call must be followed by a call to runtime.KeepAlive(h), | |
// to make sure h is not collected (and finalized) before the cgo | |
// call returns. | |
runtime.SetFinalizer(h, (*boringHMAC).finalize) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (s server) ServeMemProfile(ws *websocket.Conn) { | |
defer ws.Close() | |
var payload struct { | |
MemStats runtime.MemStats | |
GCStats debug.GCStats | |
NumGoroutine int | |
} | |
for { | |
payload.NumGoroutine = runtime.NumGoroutine() | |
runtime.ReadMemStats(&payload.MemStats) |