mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Add cancellation examples
This commit is contained in:
parent
cdb4045542
commit
0dfc2b2a53
12 changed files with 440 additions and 0 deletions
19
v3/examples/cancel-async/GreetService.go
Normal file
19
v3/examples/cancel-async/GreetService.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
}
|
||||
|
||||
// A long running operation of specified duration.
|
||||
func (*Service) LongRunning(ctx context.Context, milliseconds int) error {
|
||||
select {
|
||||
case <-time.After(time.Duration(milliseconds) * time.Millisecond):
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
5
v3/examples/cancel-async/README.md
Normal file
5
v3/examples/cancel-async/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Binding Call Cancelling Example
|
||||
|
||||
This example demonstrates how to cancel binding calls in async/await style.
|
||||
|
||||
To regenerate bindings, run `wails3 generate bindings -clean -b -d assets/bindings` in this directory.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
import * as Service from "./service.js";
|
||||
export {
|
||||
Service
|
||||
};
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create} from "/wails/runtime.js";
|
||||
|
||||
/**
|
||||
* A long running operation of specified duration.
|
||||
* @param {number} milliseconds
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function LongRunning(milliseconds) {
|
||||
return $Call.ByID(298191698, milliseconds);
|
||||
}
|
||||
134
v3/examples/cancel-async/assets/index.html
Normal file
134
v3/examples/cancel-async/assets/index.html
Normal file
File diff suppressed because one or more lines are too long
37
v3/examples/cancel-async/main.go
Normal file
37
v3/examples/cancel-async/main.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
//go:embed assets/*
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Services: []application.Service{
|
||||
application.NewService(&Service{}),
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
})
|
||||
|
||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
URL: "/",
|
||||
DevToolsEnabled: true,
|
||||
})
|
||||
|
||||
err := app.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
19
v3/examples/cancel-chaining/GreetService.go
Normal file
19
v3/examples/cancel-chaining/GreetService.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
}
|
||||
|
||||
// A long running operation of specified duration.
|
||||
func (*Service) LongRunning(ctx context.Context, milliseconds int) error {
|
||||
select {
|
||||
case <-time.After(time.Duration(milliseconds) * time.Millisecond):
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
5
v3/examples/cancel-chaining/README.md
Normal file
5
v3/examples/cancel-chaining/README.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Binding Call Cancelling Example
|
||||
|
||||
This example demonstrates how to cancel binding calls in promise chaining style.
|
||||
|
||||
To regenerate bindings, run `wails3 generate bindings -clean -b -d assets/bindings` in this directory.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
import * as Service from "./service.js";
|
||||
export {
|
||||
Service
|
||||
};
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// @ts-check
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, CancellablePromise as $CancellablePromise, Create as $Create} from "/wails/runtime.js";
|
||||
|
||||
/**
|
||||
* A long running operation of specified duration.
|
||||
* @param {number} milliseconds
|
||||
* @returns {$CancellablePromise<void>}
|
||||
*/
|
||||
export function LongRunning(milliseconds) {
|
||||
return $Call.ByID(298191698, milliseconds);
|
||||
}
|
||||
136
v3/examples/cancel-chaining/assets/index.html
Normal file
136
v3/examples/cancel-chaining/assets/index.html
Normal file
File diff suppressed because one or more lines are too long
37
v3/examples/cancel-chaining/main.go
Normal file
37
v3/examples/cancel-chaining/main.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
//go:embed assets/*
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
app := application.New(application.Options{
|
||||
Services: []application.Service{
|
||||
application.NewService(&Service{}),
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
})
|
||||
|
||||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
URL: "/",
|
||||
DevToolsEnabled: true,
|
||||
})
|
||||
|
||||
err := app.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue